ipmi_si_intf.c 78 KB

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