ipmi_si_intf.c 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701
  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 | IRQF_DISABLED,
  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 | IRQF_DISABLED,
  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. if (!add_smi(info)) {
  1605. if (try_smi_init(info))
  1606. cleanup_one_si(info);
  1607. } else {
  1608. kfree(info);
  1609. }
  1610. } else {
  1611. /* remove */
  1612. struct smi_info *e, *tmp_e;
  1613. mutex_lock(&smi_infos_lock);
  1614. list_for_each_entry_safe(e, tmp_e, &smi_infos, link) {
  1615. if (e->io.addr_type != addr_space)
  1616. continue;
  1617. if (e->si_type != si_type)
  1618. continue;
  1619. if (e->io.addr_data == addr)
  1620. cleanup_one_si(e);
  1621. }
  1622. mutex_unlock(&smi_infos_lock);
  1623. }
  1624. }
  1625. rv = len;
  1626. out:
  1627. kfree(str);
  1628. return rv;
  1629. }
  1630. static int hardcode_find_bmc(void)
  1631. {
  1632. int ret = -ENODEV;
  1633. int i;
  1634. struct smi_info *info;
  1635. for (i = 0; i < SI_MAX_PARMS; i++) {
  1636. if (!ports[i] && !addrs[i])
  1637. continue;
  1638. info = smi_info_alloc();
  1639. if (!info)
  1640. return -ENOMEM;
  1641. info->addr_source = SI_HARDCODED;
  1642. printk(KERN_INFO PFX "probing via hardcoded address\n");
  1643. if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) {
  1644. info->si_type = SI_KCS;
  1645. } else if (strcmp(si_type[i], "smic") == 0) {
  1646. info->si_type = SI_SMIC;
  1647. } else if (strcmp(si_type[i], "bt") == 0) {
  1648. info->si_type = SI_BT;
  1649. } else {
  1650. printk(KERN_WARNING PFX "Interface type specified "
  1651. "for interface %d, was invalid: %s\n",
  1652. i, si_type[i]);
  1653. kfree(info);
  1654. continue;
  1655. }
  1656. if (ports[i]) {
  1657. /* An I/O port */
  1658. info->io_setup = port_setup;
  1659. info->io.addr_data = ports[i];
  1660. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  1661. } else if (addrs[i]) {
  1662. /* A memory port */
  1663. info->io_setup = mem_setup;
  1664. info->io.addr_data = addrs[i];
  1665. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  1666. } else {
  1667. printk(KERN_WARNING PFX "Interface type specified "
  1668. "for interface %d, but port and address were "
  1669. "not set or set to zero.\n", i);
  1670. kfree(info);
  1671. continue;
  1672. }
  1673. info->io.addr = NULL;
  1674. info->io.regspacing = regspacings[i];
  1675. if (!info->io.regspacing)
  1676. info->io.regspacing = DEFAULT_REGSPACING;
  1677. info->io.regsize = regsizes[i];
  1678. if (!info->io.regsize)
  1679. info->io.regsize = DEFAULT_REGSPACING;
  1680. info->io.regshift = regshifts[i];
  1681. info->irq = irqs[i];
  1682. if (info->irq)
  1683. info->irq_setup = std_irq_setup;
  1684. info->slave_addr = slave_addrs[i];
  1685. if (!add_smi(info)) {
  1686. if (try_smi_init(info))
  1687. cleanup_one_si(info);
  1688. ret = 0;
  1689. } else {
  1690. kfree(info);
  1691. }
  1692. }
  1693. return ret;
  1694. }
  1695. #ifdef CONFIG_ACPI
  1696. #include <linux/acpi.h>
  1697. /*
  1698. * Once we get an ACPI failure, we don't try any more, because we go
  1699. * through the tables sequentially. Once we don't find a table, there
  1700. * are no more.
  1701. */
  1702. static int acpi_failure;
  1703. /* For GPE-type interrupts. */
  1704. static u32 ipmi_acpi_gpe(acpi_handle gpe_device,
  1705. u32 gpe_number, void *context)
  1706. {
  1707. struct smi_info *smi_info = context;
  1708. unsigned long flags;
  1709. #ifdef DEBUG_TIMING
  1710. struct timeval t;
  1711. #endif
  1712. spin_lock_irqsave(&(smi_info->si_lock), flags);
  1713. smi_inc_stat(smi_info, interrupts);
  1714. #ifdef DEBUG_TIMING
  1715. do_gettimeofday(&t);
  1716. printk("**ACPI_GPE: %d.%9.9d\n", t.tv_sec, t.tv_usec);
  1717. #endif
  1718. smi_event_handler(smi_info, 0);
  1719. spin_unlock_irqrestore(&(smi_info->si_lock), flags);
  1720. return ACPI_INTERRUPT_HANDLED;
  1721. }
  1722. static void acpi_gpe_irq_cleanup(struct smi_info *info)
  1723. {
  1724. if (!info->irq)
  1725. return;
  1726. acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe);
  1727. }
  1728. static int acpi_gpe_irq_setup(struct smi_info *info)
  1729. {
  1730. acpi_status status;
  1731. if (!info->irq)
  1732. return 0;
  1733. /* FIXME - is level triggered right? */
  1734. status = acpi_install_gpe_handler(NULL,
  1735. info->irq,
  1736. ACPI_GPE_LEVEL_TRIGGERED,
  1737. &ipmi_acpi_gpe,
  1738. info);
  1739. if (status != AE_OK) {
  1740. dev_warn(info->dev, "%s unable to claim ACPI GPE %d,"
  1741. " running polled\n", DEVICE_NAME, info->irq);
  1742. info->irq = 0;
  1743. return -EINVAL;
  1744. } else {
  1745. info->irq_cleanup = acpi_gpe_irq_cleanup;
  1746. dev_info(info->dev, "Using ACPI GPE %d\n", info->irq);
  1747. return 0;
  1748. }
  1749. }
  1750. /*
  1751. * Defined at
  1752. * http://h21007.www2.hp.com/portal/download/files/unprot/hpspmi.pdf
  1753. */
  1754. struct SPMITable {
  1755. s8 Signature[4];
  1756. u32 Length;
  1757. u8 Revision;
  1758. u8 Checksum;
  1759. s8 OEMID[6];
  1760. s8 OEMTableID[8];
  1761. s8 OEMRevision[4];
  1762. s8 CreatorID[4];
  1763. s8 CreatorRevision[4];
  1764. u8 InterfaceType;
  1765. u8 IPMIlegacy;
  1766. s16 SpecificationRevision;
  1767. /*
  1768. * Bit 0 - SCI interrupt supported
  1769. * Bit 1 - I/O APIC/SAPIC
  1770. */
  1771. u8 InterruptType;
  1772. /*
  1773. * If bit 0 of InterruptType is set, then this is the SCI
  1774. * interrupt in the GPEx_STS register.
  1775. */
  1776. u8 GPE;
  1777. s16 Reserved;
  1778. /*
  1779. * If bit 1 of InterruptType is set, then this is the I/O
  1780. * APIC/SAPIC interrupt.
  1781. */
  1782. u32 GlobalSystemInterrupt;
  1783. /* The actual register address. */
  1784. struct acpi_generic_address addr;
  1785. u8 UID[4];
  1786. s8 spmi_id[1]; /* A '\0' terminated array starts here. */
  1787. };
  1788. static int try_init_spmi(struct SPMITable *spmi)
  1789. {
  1790. struct smi_info *info;
  1791. if (spmi->IPMIlegacy != 1) {
  1792. printk(KERN_INFO PFX "Bad SPMI legacy %d\n", spmi->IPMIlegacy);
  1793. return -ENODEV;
  1794. }
  1795. info = smi_info_alloc();
  1796. if (!info) {
  1797. printk(KERN_ERR PFX "Could not allocate SI data (3)\n");
  1798. return -ENOMEM;
  1799. }
  1800. info->addr_source = SI_SPMI;
  1801. printk(KERN_INFO PFX "probing via SPMI\n");
  1802. /* Figure out the interface type. */
  1803. switch (spmi->InterfaceType) {
  1804. case 1: /* KCS */
  1805. info->si_type = SI_KCS;
  1806. break;
  1807. case 2: /* SMIC */
  1808. info->si_type = SI_SMIC;
  1809. break;
  1810. case 3: /* BT */
  1811. info->si_type = SI_BT;
  1812. break;
  1813. default:
  1814. printk(KERN_INFO PFX "Unknown ACPI/SPMI SI type %d\n",
  1815. spmi->InterfaceType);
  1816. kfree(info);
  1817. return -EIO;
  1818. }
  1819. if (spmi->InterruptType & 1) {
  1820. /* We've got a GPE interrupt. */
  1821. info->irq = spmi->GPE;
  1822. info->irq_setup = acpi_gpe_irq_setup;
  1823. } else if (spmi->InterruptType & 2) {
  1824. /* We've got an APIC/SAPIC interrupt. */
  1825. info->irq = spmi->GlobalSystemInterrupt;
  1826. info->irq_setup = std_irq_setup;
  1827. } else {
  1828. /* Use the default interrupt setting. */
  1829. info->irq = 0;
  1830. info->irq_setup = NULL;
  1831. }
  1832. if (spmi->addr.bit_width) {
  1833. /* A (hopefully) properly formed register bit width. */
  1834. info->io.regspacing = spmi->addr.bit_width / 8;
  1835. } else {
  1836. info->io.regspacing = DEFAULT_REGSPACING;
  1837. }
  1838. info->io.regsize = info->io.regspacing;
  1839. info->io.regshift = spmi->addr.bit_offset;
  1840. if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
  1841. info->io_setup = mem_setup;
  1842. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  1843. } else if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
  1844. info->io_setup = port_setup;
  1845. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  1846. } else {
  1847. kfree(info);
  1848. printk(KERN_WARNING PFX "Unknown ACPI I/O Address type\n");
  1849. return -EIO;
  1850. }
  1851. info->io.addr_data = spmi->addr.address;
  1852. pr_info("ipmi_si: SPMI: %s %#lx regsize %d spacing %d irq %d\n",
  1853. (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
  1854. info->io.addr_data, info->io.regsize, info->io.regspacing,
  1855. info->irq);
  1856. if (add_smi(info))
  1857. kfree(info);
  1858. return 0;
  1859. }
  1860. static void spmi_find_bmc(void)
  1861. {
  1862. acpi_status status;
  1863. struct SPMITable *spmi;
  1864. int i;
  1865. if (acpi_disabled)
  1866. return;
  1867. if (acpi_failure)
  1868. return;
  1869. for (i = 0; ; i++) {
  1870. status = acpi_get_table(ACPI_SIG_SPMI, i+1,
  1871. (struct acpi_table_header **)&spmi);
  1872. if (status != AE_OK)
  1873. return;
  1874. try_init_spmi(spmi);
  1875. }
  1876. }
  1877. static int ipmi_pnp_probe(struct pnp_dev *dev,
  1878. const struct pnp_device_id *dev_id)
  1879. {
  1880. struct acpi_device *acpi_dev;
  1881. struct smi_info *info;
  1882. struct resource *res, *res_second;
  1883. acpi_handle handle;
  1884. acpi_status status;
  1885. unsigned long long tmp;
  1886. acpi_dev = pnp_acpi_device(dev);
  1887. if (!acpi_dev)
  1888. return -ENODEV;
  1889. info = smi_info_alloc();
  1890. if (!info)
  1891. return -ENOMEM;
  1892. info->addr_source = SI_ACPI;
  1893. printk(KERN_INFO PFX "probing via ACPI\n");
  1894. handle = acpi_dev->handle;
  1895. info->addr_info.acpi_info.acpi_handle = handle;
  1896. /* _IFT tells us the interface type: KCS, BT, etc */
  1897. status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp);
  1898. if (ACPI_FAILURE(status))
  1899. goto err_free;
  1900. switch (tmp) {
  1901. case 1:
  1902. info->si_type = SI_KCS;
  1903. break;
  1904. case 2:
  1905. info->si_type = SI_SMIC;
  1906. break;
  1907. case 3:
  1908. info->si_type = SI_BT;
  1909. break;
  1910. default:
  1911. dev_info(&dev->dev, "unknown IPMI type %lld\n", tmp);
  1912. goto err_free;
  1913. }
  1914. res = pnp_get_resource(dev, IORESOURCE_IO, 0);
  1915. if (res) {
  1916. info->io_setup = port_setup;
  1917. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  1918. } else {
  1919. res = pnp_get_resource(dev, IORESOURCE_MEM, 0);
  1920. if (res) {
  1921. info->io_setup = mem_setup;
  1922. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  1923. }
  1924. }
  1925. if (!res) {
  1926. dev_err(&dev->dev, "no I/O or memory address\n");
  1927. goto err_free;
  1928. }
  1929. info->io.addr_data = res->start;
  1930. info->io.regspacing = DEFAULT_REGSPACING;
  1931. res_second = pnp_get_resource(dev,
  1932. (info->io.addr_type == IPMI_IO_ADDR_SPACE) ?
  1933. IORESOURCE_IO : IORESOURCE_MEM,
  1934. 1);
  1935. if (res_second) {
  1936. if (res_second->start > info->io.addr_data)
  1937. info->io.regspacing = res_second->start - info->io.addr_data;
  1938. }
  1939. info->io.regsize = DEFAULT_REGSPACING;
  1940. info->io.regshift = 0;
  1941. /* If _GPE exists, use it; otherwise use standard interrupts */
  1942. status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp);
  1943. if (ACPI_SUCCESS(status)) {
  1944. info->irq = tmp;
  1945. info->irq_setup = acpi_gpe_irq_setup;
  1946. } else if (pnp_irq_valid(dev, 0)) {
  1947. info->irq = pnp_irq(dev, 0);
  1948. info->irq_setup = std_irq_setup;
  1949. }
  1950. info->dev = &dev->dev;
  1951. pnp_set_drvdata(dev, info);
  1952. dev_info(info->dev, "%pR regsize %d spacing %d irq %d\n",
  1953. res, info->io.regsize, info->io.regspacing,
  1954. info->irq);
  1955. if (add_smi(info))
  1956. goto err_free;
  1957. return 0;
  1958. err_free:
  1959. kfree(info);
  1960. return -EINVAL;
  1961. }
  1962. static void ipmi_pnp_remove(struct pnp_dev *dev)
  1963. {
  1964. struct smi_info *info = pnp_get_drvdata(dev);
  1965. cleanup_one_si(info);
  1966. }
  1967. static const struct pnp_device_id pnp_dev_table[] = {
  1968. {"IPI0001", 0},
  1969. {"", 0},
  1970. };
  1971. static struct pnp_driver ipmi_pnp_driver = {
  1972. .name = DEVICE_NAME,
  1973. .probe = ipmi_pnp_probe,
  1974. .remove = ipmi_pnp_remove,
  1975. .id_table = pnp_dev_table,
  1976. };
  1977. MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
  1978. #endif
  1979. #ifdef CONFIG_DMI
  1980. struct dmi_ipmi_data {
  1981. u8 type;
  1982. u8 addr_space;
  1983. unsigned long base_addr;
  1984. u8 irq;
  1985. u8 offset;
  1986. u8 slave_addr;
  1987. };
  1988. static int decode_dmi(const struct dmi_header *dm,
  1989. struct dmi_ipmi_data *dmi)
  1990. {
  1991. const u8 *data = (const u8 *)dm;
  1992. unsigned long base_addr;
  1993. u8 reg_spacing;
  1994. u8 len = dm->length;
  1995. dmi->type = data[4];
  1996. memcpy(&base_addr, data+8, sizeof(unsigned long));
  1997. if (len >= 0x11) {
  1998. if (base_addr & 1) {
  1999. /* I/O */
  2000. base_addr &= 0xFFFE;
  2001. dmi->addr_space = IPMI_IO_ADDR_SPACE;
  2002. } else
  2003. /* Memory */
  2004. dmi->addr_space = IPMI_MEM_ADDR_SPACE;
  2005. /* If bit 4 of byte 0x10 is set, then the lsb for the address
  2006. is odd. */
  2007. dmi->base_addr = base_addr | ((data[0x10] & 0x10) >> 4);
  2008. dmi->irq = data[0x11];
  2009. /* The top two bits of byte 0x10 hold the register spacing. */
  2010. reg_spacing = (data[0x10] & 0xC0) >> 6;
  2011. switch (reg_spacing) {
  2012. case 0x00: /* Byte boundaries */
  2013. dmi->offset = 1;
  2014. break;
  2015. case 0x01: /* 32-bit boundaries */
  2016. dmi->offset = 4;
  2017. break;
  2018. case 0x02: /* 16-byte boundaries */
  2019. dmi->offset = 16;
  2020. break;
  2021. default:
  2022. /* Some other interface, just ignore it. */
  2023. return -EIO;
  2024. }
  2025. } else {
  2026. /* Old DMI spec. */
  2027. /*
  2028. * Note that technically, the lower bit of the base
  2029. * address should be 1 if the address is I/O and 0 if
  2030. * the address is in memory. So many systems get that
  2031. * wrong (and all that I have seen are I/O) so we just
  2032. * ignore that bit and assume I/O. Systems that use
  2033. * memory should use the newer spec, anyway.
  2034. */
  2035. dmi->base_addr = base_addr & 0xfffe;
  2036. dmi->addr_space = IPMI_IO_ADDR_SPACE;
  2037. dmi->offset = 1;
  2038. }
  2039. dmi->slave_addr = data[6];
  2040. return 0;
  2041. }
  2042. static void try_init_dmi(struct dmi_ipmi_data *ipmi_data)
  2043. {
  2044. struct smi_info *info;
  2045. info = smi_info_alloc();
  2046. if (!info) {
  2047. printk(KERN_ERR PFX "Could not allocate SI data\n");
  2048. return;
  2049. }
  2050. info->addr_source = SI_SMBIOS;
  2051. printk(KERN_INFO PFX "probing via SMBIOS\n");
  2052. switch (ipmi_data->type) {
  2053. case 0x01: /* KCS */
  2054. info->si_type = SI_KCS;
  2055. break;
  2056. case 0x02: /* SMIC */
  2057. info->si_type = SI_SMIC;
  2058. break;
  2059. case 0x03: /* BT */
  2060. info->si_type = SI_BT;
  2061. break;
  2062. default:
  2063. kfree(info);
  2064. return;
  2065. }
  2066. switch (ipmi_data->addr_space) {
  2067. case IPMI_MEM_ADDR_SPACE:
  2068. info->io_setup = mem_setup;
  2069. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  2070. break;
  2071. case IPMI_IO_ADDR_SPACE:
  2072. info->io_setup = port_setup;
  2073. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  2074. break;
  2075. default:
  2076. kfree(info);
  2077. printk(KERN_WARNING PFX "Unknown SMBIOS I/O Address type: %d\n",
  2078. ipmi_data->addr_space);
  2079. return;
  2080. }
  2081. info->io.addr_data = ipmi_data->base_addr;
  2082. info->io.regspacing = ipmi_data->offset;
  2083. if (!info->io.regspacing)
  2084. info->io.regspacing = DEFAULT_REGSPACING;
  2085. info->io.regsize = DEFAULT_REGSPACING;
  2086. info->io.regshift = 0;
  2087. info->slave_addr = ipmi_data->slave_addr;
  2088. info->irq = ipmi_data->irq;
  2089. if (info->irq)
  2090. info->irq_setup = std_irq_setup;
  2091. pr_info("ipmi_si: SMBIOS: %s %#lx regsize %d spacing %d irq %d\n",
  2092. (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
  2093. info->io.addr_data, info->io.regsize, info->io.regspacing,
  2094. info->irq);
  2095. if (add_smi(info))
  2096. kfree(info);
  2097. }
  2098. static void dmi_find_bmc(void)
  2099. {
  2100. const struct dmi_device *dev = NULL;
  2101. struct dmi_ipmi_data data;
  2102. int rv;
  2103. while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) {
  2104. memset(&data, 0, sizeof(data));
  2105. rv = decode_dmi((const struct dmi_header *) dev->device_data,
  2106. &data);
  2107. if (!rv)
  2108. try_init_dmi(&data);
  2109. }
  2110. }
  2111. #endif /* CONFIG_DMI */
  2112. #ifdef CONFIG_PCI
  2113. #define PCI_ERMC_CLASSCODE 0x0C0700
  2114. #define PCI_ERMC_CLASSCODE_MASK 0xffffff00
  2115. #define PCI_ERMC_CLASSCODE_TYPE_MASK 0xff
  2116. #define PCI_ERMC_CLASSCODE_TYPE_SMIC 0x00
  2117. #define PCI_ERMC_CLASSCODE_TYPE_KCS 0x01
  2118. #define PCI_ERMC_CLASSCODE_TYPE_BT 0x02
  2119. #define PCI_HP_VENDOR_ID 0x103C
  2120. #define PCI_MMC_DEVICE_ID 0x121A
  2121. #define PCI_MMC_ADDR_CW 0x10
  2122. static void ipmi_pci_cleanup(struct smi_info *info)
  2123. {
  2124. struct pci_dev *pdev = info->addr_source_data;
  2125. pci_disable_device(pdev);
  2126. }
  2127. static int ipmi_pci_probe_regspacing(struct smi_info *info)
  2128. {
  2129. if (info->si_type == SI_KCS) {
  2130. unsigned char status;
  2131. int regspacing;
  2132. info->io.regsize = DEFAULT_REGSIZE;
  2133. info->io.regshift = 0;
  2134. info->io_size = 2;
  2135. info->handlers = &kcs_smi_handlers;
  2136. /* detect 1, 4, 16byte spacing */
  2137. for (regspacing = DEFAULT_REGSPACING; regspacing <= 16;) {
  2138. info->io.regspacing = regspacing;
  2139. if (info->io_setup(info)) {
  2140. dev_err(info->dev,
  2141. "Could not setup I/O space\n");
  2142. return DEFAULT_REGSPACING;
  2143. }
  2144. /* write invalid cmd */
  2145. info->io.outputb(&info->io, 1, 0x10);
  2146. /* read status back */
  2147. status = info->io.inputb(&info->io, 1);
  2148. info->io_cleanup(info);
  2149. if (status)
  2150. return regspacing;
  2151. regspacing *= 4;
  2152. }
  2153. }
  2154. return DEFAULT_REGSPACING;
  2155. }
  2156. static int ipmi_pci_probe(struct pci_dev *pdev,
  2157. const struct pci_device_id *ent)
  2158. {
  2159. int rv;
  2160. int class_type = pdev->class & PCI_ERMC_CLASSCODE_TYPE_MASK;
  2161. struct smi_info *info;
  2162. info = smi_info_alloc();
  2163. if (!info)
  2164. return -ENOMEM;
  2165. info->addr_source = SI_PCI;
  2166. dev_info(&pdev->dev, "probing via PCI");
  2167. switch (class_type) {
  2168. case PCI_ERMC_CLASSCODE_TYPE_SMIC:
  2169. info->si_type = SI_SMIC;
  2170. break;
  2171. case PCI_ERMC_CLASSCODE_TYPE_KCS:
  2172. info->si_type = SI_KCS;
  2173. break;
  2174. case PCI_ERMC_CLASSCODE_TYPE_BT:
  2175. info->si_type = SI_BT;
  2176. break;
  2177. default:
  2178. kfree(info);
  2179. dev_info(&pdev->dev, "Unknown IPMI type: %d\n", class_type);
  2180. return -ENOMEM;
  2181. }
  2182. rv = pci_enable_device(pdev);
  2183. if (rv) {
  2184. dev_err(&pdev->dev, "couldn't enable PCI device\n");
  2185. kfree(info);
  2186. return rv;
  2187. }
  2188. info->addr_source_cleanup = ipmi_pci_cleanup;
  2189. info->addr_source_data = pdev;
  2190. if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) {
  2191. info->io_setup = port_setup;
  2192. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  2193. } else {
  2194. info->io_setup = mem_setup;
  2195. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  2196. }
  2197. info->io.addr_data = pci_resource_start(pdev, 0);
  2198. info->io.regspacing = ipmi_pci_probe_regspacing(info);
  2199. info->io.regsize = DEFAULT_REGSIZE;
  2200. info->io.regshift = 0;
  2201. info->irq = pdev->irq;
  2202. if (info->irq)
  2203. info->irq_setup = std_irq_setup;
  2204. info->dev = &pdev->dev;
  2205. pci_set_drvdata(pdev, info);
  2206. dev_info(&pdev->dev, "%pR regsize %d spacing %d irq %d\n",
  2207. &pdev->resource[0], info->io.regsize, info->io.regspacing,
  2208. info->irq);
  2209. if (add_smi(info))
  2210. kfree(info);
  2211. return 0;
  2212. }
  2213. static void ipmi_pci_remove(struct pci_dev *pdev)
  2214. {
  2215. struct smi_info *info = pci_get_drvdata(pdev);
  2216. cleanup_one_si(info);
  2217. }
  2218. static struct pci_device_id ipmi_pci_devices[] = {
  2219. { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) },
  2220. { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE_MASK) },
  2221. { 0, }
  2222. };
  2223. MODULE_DEVICE_TABLE(pci, ipmi_pci_devices);
  2224. static struct pci_driver ipmi_pci_driver = {
  2225. .name = DEVICE_NAME,
  2226. .id_table = ipmi_pci_devices,
  2227. .probe = ipmi_pci_probe,
  2228. .remove = ipmi_pci_remove,
  2229. };
  2230. #endif /* CONFIG_PCI */
  2231. static struct of_device_id ipmi_match[];
  2232. static int ipmi_probe(struct platform_device *dev)
  2233. {
  2234. #ifdef CONFIG_OF
  2235. const struct of_device_id *match;
  2236. struct smi_info *info;
  2237. struct resource resource;
  2238. const __be32 *regsize, *regspacing, *regshift;
  2239. struct device_node *np = dev->dev.of_node;
  2240. int ret;
  2241. int proplen;
  2242. dev_info(&dev->dev, "probing via device tree\n");
  2243. match = of_match_device(ipmi_match, &dev->dev);
  2244. if (!match)
  2245. return -EINVAL;
  2246. ret = of_address_to_resource(np, 0, &resource);
  2247. if (ret) {
  2248. dev_warn(&dev->dev, PFX "invalid address from OF\n");
  2249. return ret;
  2250. }
  2251. regsize = of_get_property(np, "reg-size", &proplen);
  2252. if (regsize && proplen != 4) {
  2253. dev_warn(&dev->dev, PFX "invalid regsize from OF\n");
  2254. return -EINVAL;
  2255. }
  2256. regspacing = of_get_property(np, "reg-spacing", &proplen);
  2257. if (regspacing && proplen != 4) {
  2258. dev_warn(&dev->dev, PFX "invalid regspacing from OF\n");
  2259. return -EINVAL;
  2260. }
  2261. regshift = of_get_property(np, "reg-shift", &proplen);
  2262. if (regshift && proplen != 4) {
  2263. dev_warn(&dev->dev, PFX "invalid regshift from OF\n");
  2264. return -EINVAL;
  2265. }
  2266. info = smi_info_alloc();
  2267. if (!info) {
  2268. dev_err(&dev->dev,
  2269. "could not allocate memory for OF probe\n");
  2270. return -ENOMEM;
  2271. }
  2272. info->si_type = (enum si_type) match->data;
  2273. info->addr_source = SI_DEVICETREE;
  2274. info->irq_setup = std_irq_setup;
  2275. if (resource.flags & IORESOURCE_IO) {
  2276. info->io_setup = port_setup;
  2277. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  2278. } else {
  2279. info->io_setup = mem_setup;
  2280. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  2281. }
  2282. info->io.addr_data = resource.start;
  2283. info->io.regsize = regsize ? be32_to_cpup(regsize) : DEFAULT_REGSIZE;
  2284. info->io.regspacing = regspacing ? be32_to_cpup(regspacing) : DEFAULT_REGSPACING;
  2285. info->io.regshift = regshift ? be32_to_cpup(regshift) : 0;
  2286. info->irq = irq_of_parse_and_map(dev->dev.of_node, 0);
  2287. info->dev = &dev->dev;
  2288. dev_dbg(&dev->dev, "addr 0x%lx regsize %d spacing %d irq %d\n",
  2289. info->io.addr_data, info->io.regsize, info->io.regspacing,
  2290. info->irq);
  2291. dev_set_drvdata(&dev->dev, info);
  2292. if (add_smi(info)) {
  2293. kfree(info);
  2294. return -EBUSY;
  2295. }
  2296. #endif
  2297. return 0;
  2298. }
  2299. static int ipmi_remove(struct platform_device *dev)
  2300. {
  2301. #ifdef CONFIG_OF
  2302. cleanup_one_si(dev_get_drvdata(&dev->dev));
  2303. #endif
  2304. return 0;
  2305. }
  2306. static struct of_device_id ipmi_match[] =
  2307. {
  2308. { .type = "ipmi", .compatible = "ipmi-kcs",
  2309. .data = (void *)(unsigned long) SI_KCS },
  2310. { .type = "ipmi", .compatible = "ipmi-smic",
  2311. .data = (void *)(unsigned long) SI_SMIC },
  2312. { .type = "ipmi", .compatible = "ipmi-bt",
  2313. .data = (void *)(unsigned long) SI_BT },
  2314. {},
  2315. };
  2316. static struct platform_driver ipmi_driver = {
  2317. .driver = {
  2318. .name = DEVICE_NAME,
  2319. .owner = THIS_MODULE,
  2320. .of_match_table = ipmi_match,
  2321. },
  2322. .probe = ipmi_probe,
  2323. .remove = ipmi_remove,
  2324. };
  2325. #ifdef CONFIG_PARISC
  2326. static int ipmi_parisc_probe(struct parisc_device *dev)
  2327. {
  2328. struct smi_info *info;
  2329. info = smi_info_alloc();
  2330. if (!info) {
  2331. dev_err(&dev->dev,
  2332. "could not allocate memory for PARISC probe\n");
  2333. return -ENOMEM;
  2334. }
  2335. info->si_type = SI_KCS;
  2336. info->addr_source = SI_DEVICETREE;
  2337. info->io_setup = mem_setup;
  2338. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  2339. info->io.addr_data = dev->hpa.start;
  2340. info->io.regsize = 1;
  2341. info->io.regspacing = 1;
  2342. info->io.regshift = 0;
  2343. info->irq = 0; /* no interrupt */
  2344. info->irq_setup = NULL;
  2345. info->dev = &dev->dev;
  2346. dev_dbg(&dev->dev, "addr 0x%lx\n", info->io.addr_data);
  2347. dev_set_drvdata(&dev->dev, info);
  2348. if (add_smi(info)) {
  2349. kfree(info);
  2350. return -EBUSY;
  2351. }
  2352. return 0;
  2353. }
  2354. static int ipmi_parisc_remove(struct parisc_device *dev)
  2355. {
  2356. cleanup_one_si(dev_get_drvdata(&dev->dev));
  2357. return 0;
  2358. }
  2359. static struct parisc_device_id ipmi_parisc_tbl[] = {
  2360. { HPHW_MC, HVERSION_REV_ANY_ID, 0x004, 0xC0 },
  2361. { 0, }
  2362. };
  2363. static struct parisc_driver ipmi_parisc_driver = {
  2364. .name = "ipmi",
  2365. .id_table = ipmi_parisc_tbl,
  2366. .probe = ipmi_parisc_probe,
  2367. .remove = ipmi_parisc_remove,
  2368. };
  2369. #endif /* CONFIG_PARISC */
  2370. static int wait_for_msg_done(struct smi_info *smi_info)
  2371. {
  2372. enum si_sm_result smi_result;
  2373. smi_result = smi_info->handlers->event(smi_info->si_sm, 0);
  2374. for (;;) {
  2375. if (smi_result == SI_SM_CALL_WITH_DELAY ||
  2376. smi_result == SI_SM_CALL_WITH_TICK_DELAY) {
  2377. schedule_timeout_uninterruptible(1);
  2378. smi_result = smi_info->handlers->event(
  2379. smi_info->si_sm, 100);
  2380. } else if (smi_result == SI_SM_CALL_WITHOUT_DELAY) {
  2381. smi_result = smi_info->handlers->event(
  2382. smi_info->si_sm, 0);
  2383. } else
  2384. break;
  2385. }
  2386. if (smi_result == SI_SM_HOSED)
  2387. /*
  2388. * We couldn't get the state machine to run, so whatever's at
  2389. * the port is probably not an IPMI SMI interface.
  2390. */
  2391. return -ENODEV;
  2392. return 0;
  2393. }
  2394. static int try_get_dev_id(struct smi_info *smi_info)
  2395. {
  2396. unsigned char msg[2];
  2397. unsigned char *resp;
  2398. unsigned long resp_len;
  2399. int rv = 0;
  2400. resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
  2401. if (!resp)
  2402. return -ENOMEM;
  2403. /*
  2404. * Do a Get Device ID command, since it comes back with some
  2405. * useful info.
  2406. */
  2407. msg[0] = IPMI_NETFN_APP_REQUEST << 2;
  2408. msg[1] = IPMI_GET_DEVICE_ID_CMD;
  2409. smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2);
  2410. rv = wait_for_msg_done(smi_info);
  2411. if (rv)
  2412. goto out;
  2413. resp_len = smi_info->handlers->get_result(smi_info->si_sm,
  2414. resp, IPMI_MAX_MSG_LENGTH);
  2415. /* Check and record info from the get device id, in case we need it. */
  2416. rv = ipmi_demangle_device_id(resp, resp_len, &smi_info->device_id);
  2417. out:
  2418. kfree(resp);
  2419. return rv;
  2420. }
  2421. static int try_enable_event_buffer(struct smi_info *smi_info)
  2422. {
  2423. unsigned char msg[3];
  2424. unsigned char *resp;
  2425. unsigned long resp_len;
  2426. int rv = 0;
  2427. resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
  2428. if (!resp)
  2429. return -ENOMEM;
  2430. msg[0] = IPMI_NETFN_APP_REQUEST << 2;
  2431. msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD;
  2432. smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2);
  2433. rv = wait_for_msg_done(smi_info);
  2434. if (rv) {
  2435. printk(KERN_WARNING PFX "Error getting response from get"
  2436. " global enables command, the event buffer is not"
  2437. " enabled.\n");
  2438. goto out;
  2439. }
  2440. resp_len = smi_info->handlers->get_result(smi_info->si_sm,
  2441. resp, IPMI_MAX_MSG_LENGTH);
  2442. if (resp_len < 4 ||
  2443. resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 ||
  2444. resp[1] != IPMI_GET_BMC_GLOBAL_ENABLES_CMD ||
  2445. resp[2] != 0) {
  2446. printk(KERN_WARNING PFX "Invalid return from get global"
  2447. " enables command, cannot enable the event buffer.\n");
  2448. rv = -EINVAL;
  2449. goto out;
  2450. }
  2451. if (resp[3] & IPMI_BMC_EVT_MSG_BUFF)
  2452. /* buffer is already enabled, nothing to do. */
  2453. goto out;
  2454. msg[0] = IPMI_NETFN_APP_REQUEST << 2;
  2455. msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
  2456. msg[2] = resp[3] | IPMI_BMC_EVT_MSG_BUFF;
  2457. smi_info->handlers->start_transaction(smi_info->si_sm, msg, 3);
  2458. rv = wait_for_msg_done(smi_info);
  2459. if (rv) {
  2460. printk(KERN_WARNING PFX "Error getting response from set"
  2461. " global, enables command, the event buffer is not"
  2462. " enabled.\n");
  2463. goto out;
  2464. }
  2465. resp_len = smi_info->handlers->get_result(smi_info->si_sm,
  2466. resp, IPMI_MAX_MSG_LENGTH);
  2467. if (resp_len < 3 ||
  2468. resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 ||
  2469. resp[1] != IPMI_SET_BMC_GLOBAL_ENABLES_CMD) {
  2470. printk(KERN_WARNING PFX "Invalid return from get global,"
  2471. "enables command, not enable the event buffer.\n");
  2472. rv = -EINVAL;
  2473. goto out;
  2474. }
  2475. if (resp[2] != 0)
  2476. /*
  2477. * An error when setting the event buffer bit means
  2478. * that the event buffer is not supported.
  2479. */
  2480. rv = -ENOENT;
  2481. out:
  2482. kfree(resp);
  2483. return rv;
  2484. }
  2485. static int smi_type_proc_show(struct seq_file *m, void *v)
  2486. {
  2487. struct smi_info *smi = m->private;
  2488. return seq_printf(m, "%s\n", si_to_str[smi->si_type]);
  2489. }
  2490. static int smi_type_proc_open(struct inode *inode, struct file *file)
  2491. {
  2492. return single_open(file, smi_type_proc_show, PDE_DATA(inode));
  2493. }
  2494. static const struct file_operations smi_type_proc_ops = {
  2495. .open = smi_type_proc_open,
  2496. .read = seq_read,
  2497. .llseek = seq_lseek,
  2498. .release = single_release,
  2499. };
  2500. static int smi_si_stats_proc_show(struct seq_file *m, void *v)
  2501. {
  2502. struct smi_info *smi = m->private;
  2503. seq_printf(m, "interrupts_enabled: %d\n",
  2504. smi->irq && !smi->interrupt_disabled);
  2505. seq_printf(m, "short_timeouts: %u\n",
  2506. smi_get_stat(smi, short_timeouts));
  2507. seq_printf(m, "long_timeouts: %u\n",
  2508. smi_get_stat(smi, long_timeouts));
  2509. seq_printf(m, "idles: %u\n",
  2510. smi_get_stat(smi, idles));
  2511. seq_printf(m, "interrupts: %u\n",
  2512. smi_get_stat(smi, interrupts));
  2513. seq_printf(m, "attentions: %u\n",
  2514. smi_get_stat(smi, attentions));
  2515. seq_printf(m, "flag_fetches: %u\n",
  2516. smi_get_stat(smi, flag_fetches));
  2517. seq_printf(m, "hosed_count: %u\n",
  2518. smi_get_stat(smi, hosed_count));
  2519. seq_printf(m, "complete_transactions: %u\n",
  2520. smi_get_stat(smi, complete_transactions));
  2521. seq_printf(m, "events: %u\n",
  2522. smi_get_stat(smi, events));
  2523. seq_printf(m, "watchdog_pretimeouts: %u\n",
  2524. smi_get_stat(smi, watchdog_pretimeouts));
  2525. seq_printf(m, "incoming_messages: %u\n",
  2526. smi_get_stat(smi, incoming_messages));
  2527. return 0;
  2528. }
  2529. static int smi_si_stats_proc_open(struct inode *inode, struct file *file)
  2530. {
  2531. return single_open(file, smi_si_stats_proc_show, PDE_DATA(inode));
  2532. }
  2533. static const struct file_operations smi_si_stats_proc_ops = {
  2534. .open = smi_si_stats_proc_open,
  2535. .read = seq_read,
  2536. .llseek = seq_lseek,
  2537. .release = single_release,
  2538. };
  2539. static int smi_params_proc_show(struct seq_file *m, void *v)
  2540. {
  2541. struct smi_info *smi = m->private;
  2542. return seq_printf(m,
  2543. "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n",
  2544. si_to_str[smi->si_type],
  2545. addr_space_to_str[smi->io.addr_type],
  2546. smi->io.addr_data,
  2547. smi->io.regspacing,
  2548. smi->io.regsize,
  2549. smi->io.regshift,
  2550. smi->irq,
  2551. smi->slave_addr);
  2552. }
  2553. static int smi_params_proc_open(struct inode *inode, struct file *file)
  2554. {
  2555. return single_open(file, smi_params_proc_show, PDE_DATA(inode));
  2556. }
  2557. static const struct file_operations smi_params_proc_ops = {
  2558. .open = smi_params_proc_open,
  2559. .read = seq_read,
  2560. .llseek = seq_lseek,
  2561. .release = single_release,
  2562. };
  2563. /*
  2564. * oem_data_avail_to_receive_msg_avail
  2565. * @info - smi_info structure with msg_flags set
  2566. *
  2567. * Converts flags from OEM_DATA_AVAIL to RECEIVE_MSG_AVAIL
  2568. * Returns 1 indicating need to re-run handle_flags().
  2569. */
  2570. static int oem_data_avail_to_receive_msg_avail(struct smi_info *smi_info)
  2571. {
  2572. smi_info->msg_flags = ((smi_info->msg_flags & ~OEM_DATA_AVAIL) |
  2573. RECEIVE_MSG_AVAIL);
  2574. return 1;
  2575. }
  2576. /*
  2577. * setup_dell_poweredge_oem_data_handler
  2578. * @info - smi_info.device_id must be populated
  2579. *
  2580. * Systems that match, but have firmware version < 1.40 may assert
  2581. * OEM0_DATA_AVAIL on their own, without being told via Set Flags that
  2582. * it's safe to do so. Such systems will de-assert OEM1_DATA_AVAIL
  2583. * upon receipt of IPMI_GET_MSG_CMD, so we should treat these flags
  2584. * as RECEIVE_MSG_AVAIL instead.
  2585. *
  2586. * As Dell has no plans to release IPMI 1.5 firmware that *ever*
  2587. * assert the OEM[012] bits, and if it did, the driver would have to
  2588. * change to handle that properly, we don't actually check for the
  2589. * firmware version.
  2590. * Device ID = 0x20 BMC on PowerEdge 8G servers
  2591. * Device Revision = 0x80
  2592. * Firmware Revision1 = 0x01 BMC version 1.40
  2593. * Firmware Revision2 = 0x40 BCD encoded
  2594. * IPMI Version = 0x51 IPMI 1.5
  2595. * Manufacturer ID = A2 02 00 Dell IANA
  2596. *
  2597. * Additionally, PowerEdge systems with IPMI < 1.5 may also assert
  2598. * OEM0_DATA_AVAIL and needs to be treated as RECEIVE_MSG_AVAIL.
  2599. *
  2600. */
  2601. #define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20
  2602. #define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80
  2603. #define DELL_POWEREDGE_8G_BMC_IPMI_VERSION 0x51
  2604. #define DELL_IANA_MFR_ID 0x0002a2
  2605. static void setup_dell_poweredge_oem_data_handler(struct smi_info *smi_info)
  2606. {
  2607. struct ipmi_device_id *id = &smi_info->device_id;
  2608. if (id->manufacturer_id == DELL_IANA_MFR_ID) {
  2609. if (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID &&
  2610. id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV &&
  2611. id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION) {
  2612. smi_info->oem_data_avail_handler =
  2613. oem_data_avail_to_receive_msg_avail;
  2614. } else if (ipmi_version_major(id) < 1 ||
  2615. (ipmi_version_major(id) == 1 &&
  2616. ipmi_version_minor(id) < 5)) {
  2617. smi_info->oem_data_avail_handler =
  2618. oem_data_avail_to_receive_msg_avail;
  2619. }
  2620. }
  2621. }
  2622. #define CANNOT_RETURN_REQUESTED_LENGTH 0xCA
  2623. static void return_hosed_msg_badsize(struct smi_info *smi_info)
  2624. {
  2625. struct ipmi_smi_msg *msg = smi_info->curr_msg;
  2626. /* Make it a response */
  2627. msg->rsp[0] = msg->data[0] | 4;
  2628. msg->rsp[1] = msg->data[1];
  2629. msg->rsp[2] = CANNOT_RETURN_REQUESTED_LENGTH;
  2630. msg->rsp_size = 3;
  2631. smi_info->curr_msg = NULL;
  2632. deliver_recv_msg(smi_info, msg);
  2633. }
  2634. /*
  2635. * dell_poweredge_bt_xaction_handler
  2636. * @info - smi_info.device_id must be populated
  2637. *
  2638. * Dell PowerEdge servers with the BT interface (x6xx and 1750) will
  2639. * not respond to a Get SDR command if the length of the data
  2640. * requested is exactly 0x3A, which leads to command timeouts and no
  2641. * data returned. This intercepts such commands, and causes userspace
  2642. * callers to try again with a different-sized buffer, which succeeds.
  2643. */
  2644. #define STORAGE_NETFN 0x0A
  2645. #define STORAGE_CMD_GET_SDR 0x23
  2646. static int dell_poweredge_bt_xaction_handler(struct notifier_block *self,
  2647. unsigned long unused,
  2648. void *in)
  2649. {
  2650. struct smi_info *smi_info = in;
  2651. unsigned char *data = smi_info->curr_msg->data;
  2652. unsigned int size = smi_info->curr_msg->data_size;
  2653. if (size >= 8 &&
  2654. (data[0]>>2) == STORAGE_NETFN &&
  2655. data[1] == STORAGE_CMD_GET_SDR &&
  2656. data[7] == 0x3A) {
  2657. return_hosed_msg_badsize(smi_info);
  2658. return NOTIFY_STOP;
  2659. }
  2660. return NOTIFY_DONE;
  2661. }
  2662. static struct notifier_block dell_poweredge_bt_xaction_notifier = {
  2663. .notifier_call = dell_poweredge_bt_xaction_handler,
  2664. };
  2665. /*
  2666. * setup_dell_poweredge_bt_xaction_handler
  2667. * @info - smi_info.device_id must be filled in already
  2668. *
  2669. * Fills in smi_info.device_id.start_transaction_pre_hook
  2670. * when we know what function to use there.
  2671. */
  2672. static void
  2673. setup_dell_poweredge_bt_xaction_handler(struct smi_info *smi_info)
  2674. {
  2675. struct ipmi_device_id *id = &smi_info->device_id;
  2676. if (id->manufacturer_id == DELL_IANA_MFR_ID &&
  2677. smi_info->si_type == SI_BT)
  2678. register_xaction_notifier(&dell_poweredge_bt_xaction_notifier);
  2679. }
  2680. /*
  2681. * setup_oem_data_handler
  2682. * @info - smi_info.device_id must be filled in already
  2683. *
  2684. * Fills in smi_info.device_id.oem_data_available_handler
  2685. * when we know what function to use there.
  2686. */
  2687. static void setup_oem_data_handler(struct smi_info *smi_info)
  2688. {
  2689. setup_dell_poweredge_oem_data_handler(smi_info);
  2690. }
  2691. static void setup_xaction_handlers(struct smi_info *smi_info)
  2692. {
  2693. setup_dell_poweredge_bt_xaction_handler(smi_info);
  2694. }
  2695. static inline void wait_for_timer_and_thread(struct smi_info *smi_info)
  2696. {
  2697. if (smi_info->intf) {
  2698. /*
  2699. * The timer and thread are only running if the
  2700. * interface has been started up and registered.
  2701. */
  2702. if (smi_info->thread != NULL)
  2703. kthread_stop(smi_info->thread);
  2704. del_timer_sync(&smi_info->si_timer);
  2705. }
  2706. }
  2707. static struct ipmi_default_vals
  2708. {
  2709. int type;
  2710. int port;
  2711. } ipmi_defaults[] =
  2712. {
  2713. { .type = SI_KCS, .port = 0xca2 },
  2714. { .type = SI_SMIC, .port = 0xca9 },
  2715. { .type = SI_BT, .port = 0xe4 },
  2716. { .port = 0 }
  2717. };
  2718. static void default_find_bmc(void)
  2719. {
  2720. struct smi_info *info;
  2721. int i;
  2722. for (i = 0; ; i++) {
  2723. if (!ipmi_defaults[i].port)
  2724. break;
  2725. #ifdef CONFIG_PPC
  2726. if (check_legacy_ioport(ipmi_defaults[i].port))
  2727. continue;
  2728. #endif
  2729. info = smi_info_alloc();
  2730. if (!info)
  2731. return;
  2732. info->addr_source = SI_DEFAULT;
  2733. info->si_type = ipmi_defaults[i].type;
  2734. info->io_setup = port_setup;
  2735. info->io.addr_data = ipmi_defaults[i].port;
  2736. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  2737. info->io.addr = NULL;
  2738. info->io.regspacing = DEFAULT_REGSPACING;
  2739. info->io.regsize = DEFAULT_REGSPACING;
  2740. info->io.regshift = 0;
  2741. if (add_smi(info) == 0) {
  2742. if ((try_smi_init(info)) == 0) {
  2743. /* Found one... */
  2744. printk(KERN_INFO PFX "Found default %s"
  2745. " state machine at %s address 0x%lx\n",
  2746. si_to_str[info->si_type],
  2747. addr_space_to_str[info->io.addr_type],
  2748. info->io.addr_data);
  2749. } else
  2750. cleanup_one_si(info);
  2751. } else {
  2752. kfree(info);
  2753. }
  2754. }
  2755. }
  2756. static int is_new_interface(struct smi_info *info)
  2757. {
  2758. struct smi_info *e;
  2759. list_for_each_entry(e, &smi_infos, link) {
  2760. if (e->io.addr_type != info->io.addr_type)
  2761. continue;
  2762. if (e->io.addr_data == info->io.addr_data)
  2763. return 0;
  2764. }
  2765. return 1;
  2766. }
  2767. static int add_smi(struct smi_info *new_smi)
  2768. {
  2769. int rv = 0;
  2770. printk(KERN_INFO PFX "Adding %s-specified %s state machine",
  2771. ipmi_addr_src_to_str[new_smi->addr_source],
  2772. si_to_str[new_smi->si_type]);
  2773. mutex_lock(&smi_infos_lock);
  2774. if (!is_new_interface(new_smi)) {
  2775. printk(KERN_CONT " duplicate interface\n");
  2776. rv = -EBUSY;
  2777. goto out_err;
  2778. }
  2779. printk(KERN_CONT "\n");
  2780. /* So we know not to free it unless we have allocated one. */
  2781. new_smi->intf = NULL;
  2782. new_smi->si_sm = NULL;
  2783. new_smi->handlers = NULL;
  2784. list_add_tail(&new_smi->link, &smi_infos);
  2785. out_err:
  2786. mutex_unlock(&smi_infos_lock);
  2787. return rv;
  2788. }
  2789. static int try_smi_init(struct smi_info *new_smi)
  2790. {
  2791. int rv = 0;
  2792. int i;
  2793. printk(KERN_INFO PFX "Trying %s-specified %s state"
  2794. " machine at %s address 0x%lx, slave address 0x%x,"
  2795. " irq %d\n",
  2796. ipmi_addr_src_to_str[new_smi->addr_source],
  2797. si_to_str[new_smi->si_type],
  2798. addr_space_to_str[new_smi->io.addr_type],
  2799. new_smi->io.addr_data,
  2800. new_smi->slave_addr, new_smi->irq);
  2801. switch (new_smi->si_type) {
  2802. case SI_KCS:
  2803. new_smi->handlers = &kcs_smi_handlers;
  2804. break;
  2805. case SI_SMIC:
  2806. new_smi->handlers = &smic_smi_handlers;
  2807. break;
  2808. case SI_BT:
  2809. new_smi->handlers = &bt_smi_handlers;
  2810. break;
  2811. default:
  2812. /* No support for anything else yet. */
  2813. rv = -EIO;
  2814. goto out_err;
  2815. }
  2816. /* Allocate the state machine's data and initialize it. */
  2817. new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL);
  2818. if (!new_smi->si_sm) {
  2819. printk(KERN_ERR PFX
  2820. "Could not allocate state machine memory\n");
  2821. rv = -ENOMEM;
  2822. goto out_err;
  2823. }
  2824. new_smi->io_size = new_smi->handlers->init_data(new_smi->si_sm,
  2825. &new_smi->io);
  2826. /* Now that we know the I/O size, we can set up the I/O. */
  2827. rv = new_smi->io_setup(new_smi);
  2828. if (rv) {
  2829. printk(KERN_ERR PFX "Could not set up I/O space\n");
  2830. goto out_err;
  2831. }
  2832. /* Do low-level detection first. */
  2833. if (new_smi->handlers->detect(new_smi->si_sm)) {
  2834. if (new_smi->addr_source)
  2835. printk(KERN_INFO PFX "Interface detection failed\n");
  2836. rv = -ENODEV;
  2837. goto out_err;
  2838. }
  2839. /*
  2840. * Attempt a get device id command. If it fails, we probably
  2841. * don't have a BMC here.
  2842. */
  2843. rv = try_get_dev_id(new_smi);
  2844. if (rv) {
  2845. if (new_smi->addr_source)
  2846. printk(KERN_INFO PFX "There appears to be no BMC"
  2847. " at this location\n");
  2848. goto out_err;
  2849. }
  2850. setup_oem_data_handler(new_smi);
  2851. setup_xaction_handlers(new_smi);
  2852. INIT_LIST_HEAD(&(new_smi->xmit_msgs));
  2853. INIT_LIST_HEAD(&(new_smi->hp_xmit_msgs));
  2854. new_smi->curr_msg = NULL;
  2855. atomic_set(&new_smi->req_events, 0);
  2856. new_smi->run_to_completion = 0;
  2857. for (i = 0; i < SI_NUM_STATS; i++)
  2858. atomic_set(&new_smi->stats[i], 0);
  2859. new_smi->interrupt_disabled = 1;
  2860. atomic_set(&new_smi->stop_operation, 0);
  2861. new_smi->intf_num = smi_num;
  2862. smi_num++;
  2863. rv = try_enable_event_buffer(new_smi);
  2864. if (rv == 0)
  2865. new_smi->has_event_buffer = 1;
  2866. /*
  2867. * Start clearing the flags before we enable interrupts or the
  2868. * timer to avoid racing with the timer.
  2869. */
  2870. start_clear_flags(new_smi);
  2871. /* IRQ is defined to be set when non-zero. */
  2872. if (new_smi->irq)
  2873. new_smi->si_state = SI_CLEARING_FLAGS_THEN_SET_IRQ;
  2874. if (!new_smi->dev) {
  2875. /*
  2876. * If we don't already have a device from something
  2877. * else (like PCI), then register a new one.
  2878. */
  2879. new_smi->pdev = platform_device_alloc("ipmi_si",
  2880. new_smi->intf_num);
  2881. if (!new_smi->pdev) {
  2882. printk(KERN_ERR PFX
  2883. "Unable to allocate platform device\n");
  2884. goto out_err;
  2885. }
  2886. new_smi->dev = &new_smi->pdev->dev;
  2887. new_smi->dev->driver = &ipmi_driver.driver;
  2888. rv = platform_device_add(new_smi->pdev);
  2889. if (rv) {
  2890. printk(KERN_ERR PFX
  2891. "Unable to register system interface device:"
  2892. " %d\n",
  2893. rv);
  2894. goto out_err;
  2895. }
  2896. new_smi->dev_registered = 1;
  2897. }
  2898. rv = ipmi_register_smi(&handlers,
  2899. new_smi,
  2900. &new_smi->device_id,
  2901. new_smi->dev,
  2902. "bmc",
  2903. new_smi->slave_addr);
  2904. if (rv) {
  2905. dev_err(new_smi->dev, "Unable to register device: error %d\n",
  2906. rv);
  2907. goto out_err_stop_timer;
  2908. }
  2909. rv = ipmi_smi_add_proc_entry(new_smi->intf, "type",
  2910. &smi_type_proc_ops,
  2911. new_smi);
  2912. if (rv) {
  2913. dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv);
  2914. goto out_err_stop_timer;
  2915. }
  2916. rv = ipmi_smi_add_proc_entry(new_smi->intf, "si_stats",
  2917. &smi_si_stats_proc_ops,
  2918. new_smi);
  2919. if (rv) {
  2920. dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv);
  2921. goto out_err_stop_timer;
  2922. }
  2923. rv = ipmi_smi_add_proc_entry(new_smi->intf, "params",
  2924. &smi_params_proc_ops,
  2925. new_smi);
  2926. if (rv) {
  2927. dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv);
  2928. goto out_err_stop_timer;
  2929. }
  2930. dev_info(new_smi->dev, "IPMI %s interface initialized\n",
  2931. si_to_str[new_smi->si_type]);
  2932. return 0;
  2933. out_err_stop_timer:
  2934. atomic_inc(&new_smi->stop_operation);
  2935. wait_for_timer_and_thread(new_smi);
  2936. out_err:
  2937. new_smi->interrupt_disabled = 1;
  2938. if (new_smi->intf) {
  2939. ipmi_unregister_smi(new_smi->intf);
  2940. new_smi->intf = NULL;
  2941. }
  2942. if (new_smi->irq_cleanup) {
  2943. new_smi->irq_cleanup(new_smi);
  2944. new_smi->irq_cleanup = NULL;
  2945. }
  2946. /*
  2947. * Wait until we know that we are out of any interrupt
  2948. * handlers might have been running before we freed the
  2949. * interrupt.
  2950. */
  2951. synchronize_sched();
  2952. if (new_smi->si_sm) {
  2953. if (new_smi->handlers)
  2954. new_smi->handlers->cleanup(new_smi->si_sm);
  2955. kfree(new_smi->si_sm);
  2956. new_smi->si_sm = NULL;
  2957. }
  2958. if (new_smi->addr_source_cleanup) {
  2959. new_smi->addr_source_cleanup(new_smi);
  2960. new_smi->addr_source_cleanup = NULL;
  2961. }
  2962. if (new_smi->io_cleanup) {
  2963. new_smi->io_cleanup(new_smi);
  2964. new_smi->io_cleanup = NULL;
  2965. }
  2966. if (new_smi->dev_registered) {
  2967. platform_device_unregister(new_smi->pdev);
  2968. new_smi->dev_registered = 0;
  2969. }
  2970. return rv;
  2971. }
  2972. static int init_ipmi_si(void)
  2973. {
  2974. int i;
  2975. char *str;
  2976. int rv;
  2977. struct smi_info *e;
  2978. enum ipmi_addr_src type = SI_INVALID;
  2979. if (initialized)
  2980. return 0;
  2981. initialized = 1;
  2982. if (si_tryplatform) {
  2983. rv = platform_driver_register(&ipmi_driver);
  2984. if (rv) {
  2985. printk(KERN_ERR PFX "Unable to register "
  2986. "driver: %d\n", rv);
  2987. return rv;
  2988. }
  2989. }
  2990. /* Parse out the si_type string into its components. */
  2991. str = si_type_str;
  2992. if (*str != '\0') {
  2993. for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) {
  2994. si_type[i] = str;
  2995. str = strchr(str, ',');
  2996. if (str) {
  2997. *str = '\0';
  2998. str++;
  2999. } else {
  3000. break;
  3001. }
  3002. }
  3003. }
  3004. printk(KERN_INFO "IPMI System Interface driver.\n");
  3005. /* If the user gave us a device, they presumably want us to use it */
  3006. if (!hardcode_find_bmc())
  3007. return 0;
  3008. #ifdef CONFIG_PCI
  3009. if (si_trypci) {
  3010. rv = pci_register_driver(&ipmi_pci_driver);
  3011. if (rv)
  3012. printk(KERN_ERR PFX "Unable to register "
  3013. "PCI driver: %d\n", rv);
  3014. else
  3015. pci_registered = 1;
  3016. }
  3017. #endif
  3018. #ifdef CONFIG_ACPI
  3019. if (si_tryacpi) {
  3020. pnp_register_driver(&ipmi_pnp_driver);
  3021. pnp_registered = 1;
  3022. }
  3023. #endif
  3024. #ifdef CONFIG_DMI
  3025. if (si_trydmi)
  3026. dmi_find_bmc();
  3027. #endif
  3028. #ifdef CONFIG_ACPI
  3029. if (si_tryacpi)
  3030. spmi_find_bmc();
  3031. #endif
  3032. #ifdef CONFIG_PARISC
  3033. register_parisc_driver(&ipmi_parisc_driver);
  3034. parisc_registered = 1;
  3035. /* poking PC IO addresses will crash machine, don't do it */
  3036. si_trydefaults = 0;
  3037. #endif
  3038. /* We prefer devices with interrupts, but in the case of a machine
  3039. with multiple BMCs we assume that there will be several instances
  3040. of a given type so if we succeed in registering a type then also
  3041. try to register everything else of the same type */
  3042. mutex_lock(&smi_infos_lock);
  3043. list_for_each_entry(e, &smi_infos, link) {
  3044. /* Try to register a device if it has an IRQ and we either
  3045. haven't successfully registered a device yet or this
  3046. device has the same type as one we successfully registered */
  3047. if (e->irq && (!type || e->addr_source == type)) {
  3048. if (!try_smi_init(e)) {
  3049. type = e->addr_source;
  3050. }
  3051. }
  3052. }
  3053. /* type will only have been set if we successfully registered an si */
  3054. if (type) {
  3055. mutex_unlock(&smi_infos_lock);
  3056. return 0;
  3057. }
  3058. /* Fall back to the preferred device */
  3059. list_for_each_entry(e, &smi_infos, link) {
  3060. if (!e->irq && (!type || e->addr_source == type)) {
  3061. if (!try_smi_init(e)) {
  3062. type = e->addr_source;
  3063. }
  3064. }
  3065. }
  3066. mutex_unlock(&smi_infos_lock);
  3067. if (type)
  3068. return 0;
  3069. if (si_trydefaults) {
  3070. mutex_lock(&smi_infos_lock);
  3071. if (list_empty(&smi_infos)) {
  3072. /* No BMC was found, try defaults. */
  3073. mutex_unlock(&smi_infos_lock);
  3074. default_find_bmc();
  3075. } else
  3076. mutex_unlock(&smi_infos_lock);
  3077. }
  3078. mutex_lock(&smi_infos_lock);
  3079. if (unload_when_empty && list_empty(&smi_infos)) {
  3080. mutex_unlock(&smi_infos_lock);
  3081. cleanup_ipmi_si();
  3082. printk(KERN_WARNING PFX
  3083. "Unable to find any System Interface(s)\n");
  3084. return -ENODEV;
  3085. } else {
  3086. mutex_unlock(&smi_infos_lock);
  3087. return 0;
  3088. }
  3089. }
  3090. module_init(init_ipmi_si);
  3091. static void cleanup_one_si(struct smi_info *to_clean)
  3092. {
  3093. int rv = 0;
  3094. unsigned long flags;
  3095. if (!to_clean)
  3096. return;
  3097. list_del(&to_clean->link);
  3098. /* Tell the driver that we are shutting down. */
  3099. atomic_inc(&to_clean->stop_operation);
  3100. /*
  3101. * Make sure the timer and thread are stopped and will not run
  3102. * again.
  3103. */
  3104. wait_for_timer_and_thread(to_clean);
  3105. /*
  3106. * Timeouts are stopped, now make sure the interrupts are off
  3107. * for the device. A little tricky with locks to make sure
  3108. * there are no races.
  3109. */
  3110. spin_lock_irqsave(&to_clean->si_lock, flags);
  3111. while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
  3112. spin_unlock_irqrestore(&to_clean->si_lock, flags);
  3113. poll(to_clean);
  3114. schedule_timeout_uninterruptible(1);
  3115. spin_lock_irqsave(&to_clean->si_lock, flags);
  3116. }
  3117. disable_si_irq(to_clean);
  3118. spin_unlock_irqrestore(&to_clean->si_lock, flags);
  3119. while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
  3120. poll(to_clean);
  3121. schedule_timeout_uninterruptible(1);
  3122. }
  3123. /* Clean up interrupts and make sure that everything is done. */
  3124. if (to_clean->irq_cleanup)
  3125. to_clean->irq_cleanup(to_clean);
  3126. while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
  3127. poll(to_clean);
  3128. schedule_timeout_uninterruptible(1);
  3129. }
  3130. if (to_clean->intf)
  3131. rv = ipmi_unregister_smi(to_clean->intf);
  3132. if (rv) {
  3133. printk(KERN_ERR PFX "Unable to unregister device: errno=%d\n",
  3134. rv);
  3135. }
  3136. if (to_clean->handlers)
  3137. to_clean->handlers->cleanup(to_clean->si_sm);
  3138. kfree(to_clean->si_sm);
  3139. if (to_clean->addr_source_cleanup)
  3140. to_clean->addr_source_cleanup(to_clean);
  3141. if (to_clean->io_cleanup)
  3142. to_clean->io_cleanup(to_clean);
  3143. if (to_clean->dev_registered)
  3144. platform_device_unregister(to_clean->pdev);
  3145. kfree(to_clean);
  3146. }
  3147. static void cleanup_ipmi_si(void)
  3148. {
  3149. struct smi_info *e, *tmp_e;
  3150. if (!initialized)
  3151. return;
  3152. #ifdef CONFIG_PCI
  3153. if (pci_registered)
  3154. pci_unregister_driver(&ipmi_pci_driver);
  3155. #endif
  3156. #ifdef CONFIG_ACPI
  3157. if (pnp_registered)
  3158. pnp_unregister_driver(&ipmi_pnp_driver);
  3159. #endif
  3160. #ifdef CONFIG_PARISC
  3161. if (parisc_registered)
  3162. unregister_parisc_driver(&ipmi_parisc_driver);
  3163. #endif
  3164. platform_driver_unregister(&ipmi_driver);
  3165. mutex_lock(&smi_infos_lock);
  3166. list_for_each_entry_safe(e, tmp_e, &smi_infos, link)
  3167. cleanup_one_si(e);
  3168. mutex_unlock(&smi_infos_lock);
  3169. }
  3170. module_exit(cleanup_ipmi_si);
  3171. MODULE_LICENSE("GPL");
  3172. MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
  3173. MODULE_DESCRIPTION("Interface to the IPMI driver for the KCS, SMIC, and BT"
  3174. " system interfaces.");