ipmi_msghandler.c 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194
  1. /*
  2. * ipmi_msghandler.c
  3. *
  4. * Incoming and outgoing message routing for an IPMI interface.
  5. *
  6. * Author: MontaVista Software, Inc.
  7. * Corey Minyard <minyard@mvista.com>
  8. * source@mvista.com
  9. *
  10. * Copyright 2002 MontaVista Software Inc.
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. *
  18. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  19. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  26. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  27. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * You should have received a copy of the GNU General Public License along
  30. * with this program; if not, write to the Free Software Foundation, Inc.,
  31. * 675 Mass Ave, Cambridge, MA 02139, USA.
  32. */
  33. #include <linux/module.h>
  34. #include <linux/errno.h>
  35. #include <asm/system.h>
  36. #include <linux/poll.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/mutex.h>
  39. #include <linux/slab.h>
  40. #include <linux/ipmi.h>
  41. #include <linux/ipmi_smi.h>
  42. #include <linux/notifier.h>
  43. #include <linux/init.h>
  44. #include <linux/proc_fs.h>
  45. #include <linux/rcupdate.h>
  46. #define PFX "IPMI message handler: "
  47. #define IPMI_DRIVER_VERSION "39.1"
  48. static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
  49. static int ipmi_init_msghandler(void);
  50. static int initialized;
  51. #ifdef CONFIG_PROC_FS
  52. static struct proc_dir_entry *proc_ipmi_root;
  53. #endif /* CONFIG_PROC_FS */
  54. /* Remain in auto-maintenance mode for this amount of time (in ms). */
  55. #define IPMI_MAINTENANCE_MODE_TIMEOUT 30000
  56. #define MAX_EVENTS_IN_QUEUE 25
  57. /* Don't let a message sit in a queue forever, always time it with at lest
  58. the max message timer. This is in milliseconds. */
  59. #define MAX_MSG_TIMEOUT 60000
  60. /*
  61. * The main "user" data structure.
  62. */
  63. struct ipmi_user
  64. {
  65. struct list_head link;
  66. /* Set to "0" when the user is destroyed. */
  67. int valid;
  68. struct kref refcount;
  69. /* The upper layer that handles receive messages. */
  70. struct ipmi_user_hndl *handler;
  71. void *handler_data;
  72. /* The interface this user is bound to. */
  73. ipmi_smi_t intf;
  74. /* Does this interface receive IPMI events? */
  75. int gets_events;
  76. };
  77. struct cmd_rcvr
  78. {
  79. struct list_head link;
  80. ipmi_user_t user;
  81. unsigned char netfn;
  82. unsigned char cmd;
  83. unsigned int chans;
  84. /*
  85. * This is used to form a linked lised during mass deletion.
  86. * Since this is in an RCU list, we cannot use the link above
  87. * or change any data until the RCU period completes. So we
  88. * use this next variable during mass deletion so we can have
  89. * a list and don't have to wait and restart the search on
  90. * every individual deletion of a command. */
  91. struct cmd_rcvr *next;
  92. };
  93. struct seq_table
  94. {
  95. unsigned int inuse : 1;
  96. unsigned int broadcast : 1;
  97. unsigned long timeout;
  98. unsigned long orig_timeout;
  99. unsigned int retries_left;
  100. /* To verify on an incoming send message response that this is
  101. the message that the response is for, we keep a sequence id
  102. and increment it every time we send a message. */
  103. long seqid;
  104. /* This is held so we can properly respond to the message on a
  105. timeout, and it is used to hold the temporary data for
  106. retransmission, too. */
  107. struct ipmi_recv_msg *recv_msg;
  108. };
  109. /* Store the information in a msgid (long) to allow us to find a
  110. sequence table entry from the msgid. */
  111. #define STORE_SEQ_IN_MSGID(seq, seqid) (((seq&0xff)<<26) | (seqid&0x3ffffff))
  112. #define GET_SEQ_FROM_MSGID(msgid, seq, seqid) \
  113. do { \
  114. seq = ((msgid >> 26) & 0x3f); \
  115. seqid = (msgid & 0x3fffff); \
  116. } while (0)
  117. #define NEXT_SEQID(seqid) (((seqid) + 1) & 0x3fffff)
  118. struct ipmi_channel
  119. {
  120. unsigned char medium;
  121. unsigned char protocol;
  122. /* My slave address. This is initialized to IPMI_BMC_SLAVE_ADDR,
  123. but may be changed by the user. */
  124. unsigned char address;
  125. /* My LUN. This should generally stay the SMS LUN, but just in
  126. case... */
  127. unsigned char lun;
  128. };
  129. #ifdef CONFIG_PROC_FS
  130. struct ipmi_proc_entry
  131. {
  132. char *name;
  133. struct ipmi_proc_entry *next;
  134. };
  135. #endif
  136. struct bmc_device
  137. {
  138. struct platform_device *dev;
  139. struct ipmi_device_id id;
  140. unsigned char guid[16];
  141. int guid_set;
  142. struct kref refcount;
  143. /* bmc device attributes */
  144. struct device_attribute device_id_attr;
  145. struct device_attribute provides_dev_sdrs_attr;
  146. struct device_attribute revision_attr;
  147. struct device_attribute firmware_rev_attr;
  148. struct device_attribute version_attr;
  149. struct device_attribute add_dev_support_attr;
  150. struct device_attribute manufacturer_id_attr;
  151. struct device_attribute product_id_attr;
  152. struct device_attribute guid_attr;
  153. struct device_attribute aux_firmware_rev_attr;
  154. };
  155. #define IPMI_IPMB_NUM_SEQ 64
  156. #define IPMI_MAX_CHANNELS 16
  157. struct ipmi_smi
  158. {
  159. /* What interface number are we? */
  160. int intf_num;
  161. struct kref refcount;
  162. /* Used for a list of interfaces. */
  163. struct list_head link;
  164. /* The list of upper layers that are using me. seq_lock
  165. * protects this. */
  166. struct list_head users;
  167. /* Information to supply to users. */
  168. unsigned char ipmi_version_major;
  169. unsigned char ipmi_version_minor;
  170. /* Used for wake ups at startup. */
  171. wait_queue_head_t waitq;
  172. struct bmc_device *bmc;
  173. char *my_dev_name;
  174. char *sysfs_name;
  175. /* This is the lower-layer's sender routine. Note that you
  176. * must either be holding the ipmi_interfaces_mutex or be in
  177. * an umpreemptible region to use this. You must fetch the
  178. * value into a local variable and make sure it is not NULL. */
  179. struct ipmi_smi_handlers *handlers;
  180. void *send_info;
  181. #ifdef CONFIG_PROC_FS
  182. /* A list of proc entries for this interface. */
  183. struct mutex proc_entry_lock;
  184. struct ipmi_proc_entry *proc_entries;
  185. #endif
  186. /* Driver-model device for the system interface. */
  187. struct device *si_dev;
  188. /* A table of sequence numbers for this interface. We use the
  189. sequence numbers for IPMB messages that go out of the
  190. interface to match them up with their responses. A routine
  191. is called periodically to time the items in this list. */
  192. spinlock_t seq_lock;
  193. struct seq_table seq_table[IPMI_IPMB_NUM_SEQ];
  194. int curr_seq;
  195. /* Messages that were delayed for some reason (out of memory,
  196. for instance), will go in here to be processed later in a
  197. periodic timer interrupt. */
  198. spinlock_t waiting_msgs_lock;
  199. struct list_head waiting_msgs;
  200. /* The list of command receivers that are registered for commands
  201. on this interface. */
  202. struct mutex cmd_rcvrs_mutex;
  203. struct list_head cmd_rcvrs;
  204. /* Events that were queues because no one was there to receive
  205. them. */
  206. spinlock_t events_lock; /* For dealing with event stuff. */
  207. struct list_head waiting_events;
  208. unsigned int waiting_events_count; /* How many events in queue? */
  209. int delivering_events;
  210. /* The event receiver for my BMC, only really used at panic
  211. shutdown as a place to store this. */
  212. unsigned char event_receiver;
  213. unsigned char event_receiver_lun;
  214. unsigned char local_sel_device;
  215. unsigned char local_event_generator;
  216. /* For handling of maintenance mode. */
  217. int maintenance_mode;
  218. int maintenance_mode_enable;
  219. int auto_maintenance_timeout;
  220. spinlock_t maintenance_mode_lock; /* Used in a timer... */
  221. /* A cheap hack, if this is non-null and a message to an
  222. interface comes in with a NULL user, call this routine with
  223. it. Note that the message will still be freed by the
  224. caller. This only works on the system interface. */
  225. void (*null_user_handler)(ipmi_smi_t intf, struct ipmi_recv_msg *msg);
  226. /* When we are scanning the channels for an SMI, this will
  227. tell which channel we are scanning. */
  228. int curr_channel;
  229. /* Channel information */
  230. struct ipmi_channel channels[IPMI_MAX_CHANNELS];
  231. /* Proc FS stuff. */
  232. struct proc_dir_entry *proc_dir;
  233. char proc_dir_name[10];
  234. spinlock_t counter_lock; /* For making counters atomic. */
  235. /* Commands we got that were invalid. */
  236. unsigned int sent_invalid_commands;
  237. /* Commands we sent to the MC. */
  238. unsigned int sent_local_commands;
  239. /* Responses from the MC that were delivered to a user. */
  240. unsigned int handled_local_responses;
  241. /* Responses from the MC that were not delivered to a user. */
  242. unsigned int unhandled_local_responses;
  243. /* Commands we sent out to the IPMB bus. */
  244. unsigned int sent_ipmb_commands;
  245. /* Commands sent on the IPMB that had errors on the SEND CMD */
  246. unsigned int sent_ipmb_command_errs;
  247. /* Each retransmit increments this count. */
  248. unsigned int retransmitted_ipmb_commands;
  249. /* When a message times out (runs out of retransmits) this is
  250. incremented. */
  251. unsigned int timed_out_ipmb_commands;
  252. /* This is like above, but for broadcasts. Broadcasts are
  253. *not* included in the above count (they are expected to
  254. time out). */
  255. unsigned int timed_out_ipmb_broadcasts;
  256. /* Responses I have sent to the IPMB bus. */
  257. unsigned int sent_ipmb_responses;
  258. /* The response was delivered to the user. */
  259. unsigned int handled_ipmb_responses;
  260. /* The response had invalid data in it. */
  261. unsigned int invalid_ipmb_responses;
  262. /* The response didn't have anyone waiting for it. */
  263. unsigned int unhandled_ipmb_responses;
  264. /* Commands we sent out to the IPMB bus. */
  265. unsigned int sent_lan_commands;
  266. /* Commands sent on the IPMB that had errors on the SEND CMD */
  267. unsigned int sent_lan_command_errs;
  268. /* Each retransmit increments this count. */
  269. unsigned int retransmitted_lan_commands;
  270. /* When a message times out (runs out of retransmits) this is
  271. incremented. */
  272. unsigned int timed_out_lan_commands;
  273. /* Responses I have sent to the IPMB bus. */
  274. unsigned int sent_lan_responses;
  275. /* The response was delivered to the user. */
  276. unsigned int handled_lan_responses;
  277. /* The response had invalid data in it. */
  278. unsigned int invalid_lan_responses;
  279. /* The response didn't have anyone waiting for it. */
  280. unsigned int unhandled_lan_responses;
  281. /* The command was delivered to the user. */
  282. unsigned int handled_commands;
  283. /* The command had invalid data in it. */
  284. unsigned int invalid_commands;
  285. /* The command didn't have anyone waiting for it. */
  286. unsigned int unhandled_commands;
  287. /* Invalid data in an event. */
  288. unsigned int invalid_events;
  289. /* Events that were received with the proper format. */
  290. unsigned int events;
  291. };
  292. #define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev)
  293. /**
  294. * The driver model view of the IPMI messaging driver.
  295. */
  296. static struct device_driver ipmidriver = {
  297. .name = "ipmi",
  298. .bus = &platform_bus_type
  299. };
  300. static DEFINE_MUTEX(ipmidriver_mutex);
  301. static struct list_head ipmi_interfaces = LIST_HEAD_INIT(ipmi_interfaces);
  302. static DEFINE_MUTEX(ipmi_interfaces_mutex);
  303. /* List of watchers that want to know when smi's are added and
  304. deleted. */
  305. static struct list_head smi_watchers = LIST_HEAD_INIT(smi_watchers);
  306. static DEFINE_MUTEX(smi_watchers_mutex);
  307. static void free_recv_msg_list(struct list_head *q)
  308. {
  309. struct ipmi_recv_msg *msg, *msg2;
  310. list_for_each_entry_safe(msg, msg2, q, link) {
  311. list_del(&msg->link);
  312. ipmi_free_recv_msg(msg);
  313. }
  314. }
  315. static void free_smi_msg_list(struct list_head *q)
  316. {
  317. struct ipmi_smi_msg *msg, *msg2;
  318. list_for_each_entry_safe(msg, msg2, q, link) {
  319. list_del(&msg->link);
  320. ipmi_free_smi_msg(msg);
  321. }
  322. }
  323. static void clean_up_interface_data(ipmi_smi_t intf)
  324. {
  325. int i;
  326. struct cmd_rcvr *rcvr, *rcvr2;
  327. struct list_head list;
  328. free_smi_msg_list(&intf->waiting_msgs);
  329. free_recv_msg_list(&intf->waiting_events);
  330. /*
  331. * Wholesale remove all the entries from the list in the
  332. * interface and wait for RCU to know that none are in use.
  333. */
  334. mutex_lock(&intf->cmd_rcvrs_mutex);
  335. INIT_LIST_HEAD(&list);
  336. list_splice_init_rcu(&intf->cmd_rcvrs, &list, synchronize_rcu);
  337. mutex_unlock(&intf->cmd_rcvrs_mutex);
  338. list_for_each_entry_safe(rcvr, rcvr2, &list, link)
  339. kfree(rcvr);
  340. for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
  341. if ((intf->seq_table[i].inuse)
  342. && (intf->seq_table[i].recv_msg))
  343. {
  344. ipmi_free_recv_msg(intf->seq_table[i].recv_msg);
  345. }
  346. }
  347. }
  348. static void intf_free(struct kref *ref)
  349. {
  350. ipmi_smi_t intf = container_of(ref, struct ipmi_smi, refcount);
  351. clean_up_interface_data(intf);
  352. kfree(intf);
  353. }
  354. struct watcher_entry {
  355. int intf_num;
  356. ipmi_smi_t intf;
  357. struct list_head link;
  358. };
  359. int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
  360. {
  361. ipmi_smi_t intf;
  362. struct list_head to_deliver = LIST_HEAD_INIT(to_deliver);
  363. struct watcher_entry *e, *e2;
  364. mutex_lock(&smi_watchers_mutex);
  365. mutex_lock(&ipmi_interfaces_mutex);
  366. /* Build a list of things to deliver. */
  367. list_for_each_entry(intf, &ipmi_interfaces, link) {
  368. if (intf->intf_num == -1)
  369. continue;
  370. e = kmalloc(sizeof(*e), GFP_KERNEL);
  371. if (!e)
  372. goto out_err;
  373. kref_get(&intf->refcount);
  374. e->intf = intf;
  375. e->intf_num = intf->intf_num;
  376. list_add_tail(&e->link, &to_deliver);
  377. }
  378. /* We will succeed, so add it to the list. */
  379. list_add(&watcher->link, &smi_watchers);
  380. mutex_unlock(&ipmi_interfaces_mutex);
  381. list_for_each_entry_safe(e, e2, &to_deliver, link) {
  382. list_del(&e->link);
  383. watcher->new_smi(e->intf_num, e->intf->si_dev);
  384. kref_put(&e->intf->refcount, intf_free);
  385. kfree(e);
  386. }
  387. mutex_unlock(&smi_watchers_mutex);
  388. return 0;
  389. out_err:
  390. mutex_unlock(&ipmi_interfaces_mutex);
  391. mutex_unlock(&smi_watchers_mutex);
  392. list_for_each_entry_safe(e, e2, &to_deliver, link) {
  393. list_del(&e->link);
  394. kref_put(&e->intf->refcount, intf_free);
  395. kfree(e);
  396. }
  397. return -ENOMEM;
  398. }
  399. int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher)
  400. {
  401. mutex_lock(&smi_watchers_mutex);
  402. list_del(&(watcher->link));
  403. mutex_unlock(&smi_watchers_mutex);
  404. return 0;
  405. }
  406. /*
  407. * Must be called with smi_watchers_mutex held.
  408. */
  409. static void
  410. call_smi_watchers(int i, struct device *dev)
  411. {
  412. struct ipmi_smi_watcher *w;
  413. list_for_each_entry(w, &smi_watchers, link) {
  414. if (try_module_get(w->owner)) {
  415. w->new_smi(i, dev);
  416. module_put(w->owner);
  417. }
  418. }
  419. }
  420. static int
  421. ipmi_addr_equal(struct ipmi_addr *addr1, struct ipmi_addr *addr2)
  422. {
  423. if (addr1->addr_type != addr2->addr_type)
  424. return 0;
  425. if (addr1->channel != addr2->channel)
  426. return 0;
  427. if (addr1->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) {
  428. struct ipmi_system_interface_addr *smi_addr1
  429. = (struct ipmi_system_interface_addr *) addr1;
  430. struct ipmi_system_interface_addr *smi_addr2
  431. = (struct ipmi_system_interface_addr *) addr2;
  432. return (smi_addr1->lun == smi_addr2->lun);
  433. }
  434. if ((addr1->addr_type == IPMI_IPMB_ADDR_TYPE)
  435. || (addr1->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE))
  436. {
  437. struct ipmi_ipmb_addr *ipmb_addr1
  438. = (struct ipmi_ipmb_addr *) addr1;
  439. struct ipmi_ipmb_addr *ipmb_addr2
  440. = (struct ipmi_ipmb_addr *) addr2;
  441. return ((ipmb_addr1->slave_addr == ipmb_addr2->slave_addr)
  442. && (ipmb_addr1->lun == ipmb_addr2->lun));
  443. }
  444. if (addr1->addr_type == IPMI_LAN_ADDR_TYPE) {
  445. struct ipmi_lan_addr *lan_addr1
  446. = (struct ipmi_lan_addr *) addr1;
  447. struct ipmi_lan_addr *lan_addr2
  448. = (struct ipmi_lan_addr *) addr2;
  449. return ((lan_addr1->remote_SWID == lan_addr2->remote_SWID)
  450. && (lan_addr1->local_SWID == lan_addr2->local_SWID)
  451. && (lan_addr1->session_handle
  452. == lan_addr2->session_handle)
  453. && (lan_addr1->lun == lan_addr2->lun));
  454. }
  455. return 1;
  456. }
  457. int ipmi_validate_addr(struct ipmi_addr *addr, int len)
  458. {
  459. if (len < sizeof(struct ipmi_system_interface_addr)) {
  460. return -EINVAL;
  461. }
  462. if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) {
  463. if (addr->channel != IPMI_BMC_CHANNEL)
  464. return -EINVAL;
  465. return 0;
  466. }
  467. if ((addr->channel == IPMI_BMC_CHANNEL)
  468. || (addr->channel >= IPMI_MAX_CHANNELS)
  469. || (addr->channel < 0))
  470. return -EINVAL;
  471. if ((addr->addr_type == IPMI_IPMB_ADDR_TYPE)
  472. || (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE))
  473. {
  474. if (len < sizeof(struct ipmi_ipmb_addr)) {
  475. return -EINVAL;
  476. }
  477. return 0;
  478. }
  479. if (addr->addr_type == IPMI_LAN_ADDR_TYPE) {
  480. if (len < sizeof(struct ipmi_lan_addr)) {
  481. return -EINVAL;
  482. }
  483. return 0;
  484. }
  485. return -EINVAL;
  486. }
  487. unsigned int ipmi_addr_length(int addr_type)
  488. {
  489. if (addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
  490. return sizeof(struct ipmi_system_interface_addr);
  491. if ((addr_type == IPMI_IPMB_ADDR_TYPE)
  492. || (addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE))
  493. {
  494. return sizeof(struct ipmi_ipmb_addr);
  495. }
  496. if (addr_type == IPMI_LAN_ADDR_TYPE)
  497. return sizeof(struct ipmi_lan_addr);
  498. return 0;
  499. }
  500. static void deliver_response(struct ipmi_recv_msg *msg)
  501. {
  502. if (!msg->user) {
  503. ipmi_smi_t intf = msg->user_msg_data;
  504. unsigned long flags;
  505. /* Special handling for NULL users. */
  506. if (intf->null_user_handler) {
  507. intf->null_user_handler(intf, msg);
  508. spin_lock_irqsave(&intf->counter_lock, flags);
  509. intf->handled_local_responses++;
  510. spin_unlock_irqrestore(&intf->counter_lock, flags);
  511. } else {
  512. /* No handler, so give up. */
  513. spin_lock_irqsave(&intf->counter_lock, flags);
  514. intf->unhandled_local_responses++;
  515. spin_unlock_irqrestore(&intf->counter_lock, flags);
  516. }
  517. ipmi_free_recv_msg(msg);
  518. } else {
  519. ipmi_user_t user = msg->user;
  520. user->handler->ipmi_recv_hndl(msg, user->handler_data);
  521. }
  522. }
  523. static void
  524. deliver_err_response(struct ipmi_recv_msg *msg, int err)
  525. {
  526. msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
  527. msg->msg_data[0] = err;
  528. msg->msg.netfn |= 1; /* Convert to a response. */
  529. msg->msg.data_len = 1;
  530. msg->msg.data = msg->msg_data;
  531. deliver_response(msg);
  532. }
  533. /* Find the next sequence number not being used and add the given
  534. message with the given timeout to the sequence table. This must be
  535. called with the interface's seq_lock held. */
  536. static int intf_next_seq(ipmi_smi_t intf,
  537. struct ipmi_recv_msg *recv_msg,
  538. unsigned long timeout,
  539. int retries,
  540. int broadcast,
  541. unsigned char *seq,
  542. long *seqid)
  543. {
  544. int rv = 0;
  545. unsigned int i;
  546. for (i = intf->curr_seq;
  547. (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq;
  548. i = (i+1)%IPMI_IPMB_NUM_SEQ)
  549. {
  550. if (!intf->seq_table[i].inuse)
  551. break;
  552. }
  553. if (!intf->seq_table[i].inuse) {
  554. intf->seq_table[i].recv_msg = recv_msg;
  555. /* Start with the maximum timeout, when the send response
  556. comes in we will start the real timer. */
  557. intf->seq_table[i].timeout = MAX_MSG_TIMEOUT;
  558. intf->seq_table[i].orig_timeout = timeout;
  559. intf->seq_table[i].retries_left = retries;
  560. intf->seq_table[i].broadcast = broadcast;
  561. intf->seq_table[i].inuse = 1;
  562. intf->seq_table[i].seqid = NEXT_SEQID(intf->seq_table[i].seqid);
  563. *seq = i;
  564. *seqid = intf->seq_table[i].seqid;
  565. intf->curr_seq = (i+1)%IPMI_IPMB_NUM_SEQ;
  566. } else {
  567. rv = -EAGAIN;
  568. }
  569. return rv;
  570. }
  571. /* Return the receive message for the given sequence number and
  572. release the sequence number so it can be reused. Some other data
  573. is passed in to be sure the message matches up correctly (to help
  574. guard against message coming in after their timeout and the
  575. sequence number being reused). */
  576. static int intf_find_seq(ipmi_smi_t intf,
  577. unsigned char seq,
  578. short channel,
  579. unsigned char cmd,
  580. unsigned char netfn,
  581. struct ipmi_addr *addr,
  582. struct ipmi_recv_msg **recv_msg)
  583. {
  584. int rv = -ENODEV;
  585. unsigned long flags;
  586. if (seq >= IPMI_IPMB_NUM_SEQ)
  587. return -EINVAL;
  588. spin_lock_irqsave(&(intf->seq_lock), flags);
  589. if (intf->seq_table[seq].inuse) {
  590. struct ipmi_recv_msg *msg = intf->seq_table[seq].recv_msg;
  591. if ((msg->addr.channel == channel)
  592. && (msg->msg.cmd == cmd)
  593. && (msg->msg.netfn == netfn)
  594. && (ipmi_addr_equal(addr, &(msg->addr))))
  595. {
  596. *recv_msg = msg;
  597. intf->seq_table[seq].inuse = 0;
  598. rv = 0;
  599. }
  600. }
  601. spin_unlock_irqrestore(&(intf->seq_lock), flags);
  602. return rv;
  603. }
  604. /* Start the timer for a specific sequence table entry. */
  605. static int intf_start_seq_timer(ipmi_smi_t intf,
  606. long msgid)
  607. {
  608. int rv = -ENODEV;
  609. unsigned long flags;
  610. unsigned char seq;
  611. unsigned long seqid;
  612. GET_SEQ_FROM_MSGID(msgid, seq, seqid);
  613. spin_lock_irqsave(&(intf->seq_lock), flags);
  614. /* We do this verification because the user can be deleted
  615. while a message is outstanding. */
  616. if ((intf->seq_table[seq].inuse)
  617. && (intf->seq_table[seq].seqid == seqid))
  618. {
  619. struct seq_table *ent = &(intf->seq_table[seq]);
  620. ent->timeout = ent->orig_timeout;
  621. rv = 0;
  622. }
  623. spin_unlock_irqrestore(&(intf->seq_lock), flags);
  624. return rv;
  625. }
  626. /* Got an error for the send message for a specific sequence number. */
  627. static int intf_err_seq(ipmi_smi_t intf,
  628. long msgid,
  629. unsigned int err)
  630. {
  631. int rv = -ENODEV;
  632. unsigned long flags;
  633. unsigned char seq;
  634. unsigned long seqid;
  635. struct ipmi_recv_msg *msg = NULL;
  636. GET_SEQ_FROM_MSGID(msgid, seq, seqid);
  637. spin_lock_irqsave(&(intf->seq_lock), flags);
  638. /* We do this verification because the user can be deleted
  639. while a message is outstanding. */
  640. if ((intf->seq_table[seq].inuse)
  641. && (intf->seq_table[seq].seqid == seqid))
  642. {
  643. struct seq_table *ent = &(intf->seq_table[seq]);
  644. ent->inuse = 0;
  645. msg = ent->recv_msg;
  646. rv = 0;
  647. }
  648. spin_unlock_irqrestore(&(intf->seq_lock), flags);
  649. if (msg)
  650. deliver_err_response(msg, err);
  651. return rv;
  652. }
  653. int ipmi_create_user(unsigned int if_num,
  654. struct ipmi_user_hndl *handler,
  655. void *handler_data,
  656. ipmi_user_t *user)
  657. {
  658. unsigned long flags;
  659. ipmi_user_t new_user;
  660. int rv = 0;
  661. ipmi_smi_t intf;
  662. /* There is no module usecount here, because it's not
  663. required. Since this can only be used by and called from
  664. other modules, they will implicitly use this module, and
  665. thus this can't be removed unless the other modules are
  666. removed. */
  667. if (handler == NULL)
  668. return -EINVAL;
  669. /* Make sure the driver is actually initialized, this handles
  670. problems with initialization order. */
  671. if (!initialized) {
  672. rv = ipmi_init_msghandler();
  673. if (rv)
  674. return rv;
  675. /* The init code doesn't return an error if it was turned
  676. off, but it won't initialize. Check that. */
  677. if (!initialized)
  678. return -ENODEV;
  679. }
  680. new_user = kmalloc(sizeof(*new_user), GFP_KERNEL);
  681. if (!new_user)
  682. return -ENOMEM;
  683. mutex_lock(&ipmi_interfaces_mutex);
  684. list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
  685. if (intf->intf_num == if_num)
  686. goto found;
  687. }
  688. /* Not found, return an error */
  689. rv = -EINVAL;
  690. goto out_kfree;
  691. found:
  692. /* Note that each existing user holds a refcount to the interface. */
  693. kref_get(&intf->refcount);
  694. kref_init(&new_user->refcount);
  695. new_user->handler = handler;
  696. new_user->handler_data = handler_data;
  697. new_user->intf = intf;
  698. new_user->gets_events = 0;
  699. if (!try_module_get(intf->handlers->owner)) {
  700. rv = -ENODEV;
  701. goto out_kref;
  702. }
  703. if (intf->handlers->inc_usecount) {
  704. rv = intf->handlers->inc_usecount(intf->send_info);
  705. if (rv) {
  706. module_put(intf->handlers->owner);
  707. goto out_kref;
  708. }
  709. }
  710. /* Hold the lock so intf->handlers is guaranteed to be good
  711. * until now */
  712. mutex_unlock(&ipmi_interfaces_mutex);
  713. new_user->valid = 1;
  714. spin_lock_irqsave(&intf->seq_lock, flags);
  715. list_add_rcu(&new_user->link, &intf->users);
  716. spin_unlock_irqrestore(&intf->seq_lock, flags);
  717. *user = new_user;
  718. return 0;
  719. out_kref:
  720. kref_put(&intf->refcount, intf_free);
  721. out_kfree:
  722. mutex_unlock(&ipmi_interfaces_mutex);
  723. kfree(new_user);
  724. return rv;
  725. }
  726. static void free_user(struct kref *ref)
  727. {
  728. ipmi_user_t user = container_of(ref, struct ipmi_user, refcount);
  729. kfree(user);
  730. }
  731. int ipmi_destroy_user(ipmi_user_t user)
  732. {
  733. ipmi_smi_t intf = user->intf;
  734. int i;
  735. unsigned long flags;
  736. struct cmd_rcvr *rcvr;
  737. struct cmd_rcvr *rcvrs = NULL;
  738. user->valid = 0;
  739. /* Remove the user from the interface's sequence table. */
  740. spin_lock_irqsave(&intf->seq_lock, flags);
  741. list_del_rcu(&user->link);
  742. for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
  743. if (intf->seq_table[i].inuse
  744. && (intf->seq_table[i].recv_msg->user == user))
  745. {
  746. intf->seq_table[i].inuse = 0;
  747. ipmi_free_recv_msg(intf->seq_table[i].recv_msg);
  748. }
  749. }
  750. spin_unlock_irqrestore(&intf->seq_lock, flags);
  751. /*
  752. * Remove the user from the command receiver's table. First
  753. * we build a list of everything (not using the standard link,
  754. * since other things may be using it till we do
  755. * synchronize_rcu()) then free everything in that list.
  756. */
  757. mutex_lock(&intf->cmd_rcvrs_mutex);
  758. list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
  759. if (rcvr->user == user) {
  760. list_del_rcu(&rcvr->link);
  761. rcvr->next = rcvrs;
  762. rcvrs = rcvr;
  763. }
  764. }
  765. mutex_unlock(&intf->cmd_rcvrs_mutex);
  766. synchronize_rcu();
  767. while (rcvrs) {
  768. rcvr = rcvrs;
  769. rcvrs = rcvr->next;
  770. kfree(rcvr);
  771. }
  772. mutex_lock(&ipmi_interfaces_mutex);
  773. if (intf->handlers) {
  774. module_put(intf->handlers->owner);
  775. if (intf->handlers->dec_usecount)
  776. intf->handlers->dec_usecount(intf->send_info);
  777. }
  778. mutex_unlock(&ipmi_interfaces_mutex);
  779. kref_put(&intf->refcount, intf_free);
  780. kref_put(&user->refcount, free_user);
  781. return 0;
  782. }
  783. void ipmi_get_version(ipmi_user_t user,
  784. unsigned char *major,
  785. unsigned char *minor)
  786. {
  787. *major = user->intf->ipmi_version_major;
  788. *minor = user->intf->ipmi_version_minor;
  789. }
  790. int ipmi_set_my_address(ipmi_user_t user,
  791. unsigned int channel,
  792. unsigned char address)
  793. {
  794. if (channel >= IPMI_MAX_CHANNELS)
  795. return -EINVAL;
  796. user->intf->channels[channel].address = address;
  797. return 0;
  798. }
  799. int ipmi_get_my_address(ipmi_user_t user,
  800. unsigned int channel,
  801. unsigned char *address)
  802. {
  803. if (channel >= IPMI_MAX_CHANNELS)
  804. return -EINVAL;
  805. *address = user->intf->channels[channel].address;
  806. return 0;
  807. }
  808. int ipmi_set_my_LUN(ipmi_user_t user,
  809. unsigned int channel,
  810. unsigned char LUN)
  811. {
  812. if (channel >= IPMI_MAX_CHANNELS)
  813. return -EINVAL;
  814. user->intf->channels[channel].lun = LUN & 0x3;
  815. return 0;
  816. }
  817. int ipmi_get_my_LUN(ipmi_user_t user,
  818. unsigned int channel,
  819. unsigned char *address)
  820. {
  821. if (channel >= IPMI_MAX_CHANNELS)
  822. return -EINVAL;
  823. *address = user->intf->channels[channel].lun;
  824. return 0;
  825. }
  826. int ipmi_get_maintenance_mode(ipmi_user_t user)
  827. {
  828. int mode;
  829. unsigned long flags;
  830. spin_lock_irqsave(&user->intf->maintenance_mode_lock, flags);
  831. mode = user->intf->maintenance_mode;
  832. spin_unlock_irqrestore(&user->intf->maintenance_mode_lock, flags);
  833. return mode;
  834. }
  835. EXPORT_SYMBOL(ipmi_get_maintenance_mode);
  836. static void maintenance_mode_update(ipmi_smi_t intf)
  837. {
  838. if (intf->handlers->set_maintenance_mode)
  839. intf->handlers->set_maintenance_mode(
  840. intf->send_info, intf->maintenance_mode_enable);
  841. }
  842. int ipmi_set_maintenance_mode(ipmi_user_t user, int mode)
  843. {
  844. int rv = 0;
  845. unsigned long flags;
  846. ipmi_smi_t intf = user->intf;
  847. spin_lock_irqsave(&intf->maintenance_mode_lock, flags);
  848. if (intf->maintenance_mode != mode) {
  849. switch (mode) {
  850. case IPMI_MAINTENANCE_MODE_AUTO:
  851. intf->maintenance_mode = mode;
  852. intf->maintenance_mode_enable
  853. = (intf->auto_maintenance_timeout > 0);
  854. break;
  855. case IPMI_MAINTENANCE_MODE_OFF:
  856. intf->maintenance_mode = mode;
  857. intf->maintenance_mode_enable = 0;
  858. break;
  859. case IPMI_MAINTENANCE_MODE_ON:
  860. intf->maintenance_mode = mode;
  861. intf->maintenance_mode_enable = 1;
  862. break;
  863. default:
  864. rv = -EINVAL;
  865. goto out_unlock;
  866. }
  867. maintenance_mode_update(intf);
  868. }
  869. out_unlock:
  870. spin_unlock_irqrestore(&intf->maintenance_mode_lock, flags);
  871. return rv;
  872. }
  873. EXPORT_SYMBOL(ipmi_set_maintenance_mode);
  874. int ipmi_set_gets_events(ipmi_user_t user, int val)
  875. {
  876. unsigned long flags;
  877. ipmi_smi_t intf = user->intf;
  878. struct ipmi_recv_msg *msg, *msg2;
  879. struct list_head msgs;
  880. INIT_LIST_HEAD(&msgs);
  881. spin_lock_irqsave(&intf->events_lock, flags);
  882. user->gets_events = val;
  883. if (intf->delivering_events)
  884. /*
  885. * Another thread is delivering events for this, so
  886. * let it handle any new events.
  887. */
  888. goto out;
  889. /* Deliver any queued events. */
  890. while (user->gets_events && !list_empty(&intf->waiting_events)) {
  891. list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link)
  892. list_move_tail(&msg->link, &msgs);
  893. intf->waiting_events_count = 0;
  894. intf->delivering_events = 1;
  895. spin_unlock_irqrestore(&intf->events_lock, flags);
  896. list_for_each_entry_safe(msg, msg2, &msgs, link) {
  897. msg->user = user;
  898. kref_get(&user->refcount);
  899. deliver_response(msg);
  900. }
  901. spin_lock_irqsave(&intf->events_lock, flags);
  902. intf->delivering_events = 0;
  903. }
  904. out:
  905. spin_unlock_irqrestore(&intf->events_lock, flags);
  906. return 0;
  907. }
  908. static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf,
  909. unsigned char netfn,
  910. unsigned char cmd,
  911. unsigned char chan)
  912. {
  913. struct cmd_rcvr *rcvr;
  914. list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
  915. if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)
  916. && (rcvr->chans & (1 << chan)))
  917. return rcvr;
  918. }
  919. return NULL;
  920. }
  921. static int is_cmd_rcvr_exclusive(ipmi_smi_t intf,
  922. unsigned char netfn,
  923. unsigned char cmd,
  924. unsigned int chans)
  925. {
  926. struct cmd_rcvr *rcvr;
  927. list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
  928. if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)
  929. && (rcvr->chans & chans))
  930. return 0;
  931. }
  932. return 1;
  933. }
  934. int ipmi_register_for_cmd(ipmi_user_t user,
  935. unsigned char netfn,
  936. unsigned char cmd,
  937. unsigned int chans)
  938. {
  939. ipmi_smi_t intf = user->intf;
  940. struct cmd_rcvr *rcvr;
  941. int rv = 0;
  942. rcvr = kmalloc(sizeof(*rcvr), GFP_KERNEL);
  943. if (!rcvr)
  944. return -ENOMEM;
  945. rcvr->cmd = cmd;
  946. rcvr->netfn = netfn;
  947. rcvr->chans = chans;
  948. rcvr->user = user;
  949. mutex_lock(&intf->cmd_rcvrs_mutex);
  950. /* Make sure the command/netfn is not already registered. */
  951. if (!is_cmd_rcvr_exclusive(intf, netfn, cmd, chans)) {
  952. rv = -EBUSY;
  953. goto out_unlock;
  954. }
  955. list_add_rcu(&rcvr->link, &intf->cmd_rcvrs);
  956. out_unlock:
  957. mutex_unlock(&intf->cmd_rcvrs_mutex);
  958. if (rv)
  959. kfree(rcvr);
  960. return rv;
  961. }
  962. int ipmi_unregister_for_cmd(ipmi_user_t user,
  963. unsigned char netfn,
  964. unsigned char cmd,
  965. unsigned int chans)
  966. {
  967. ipmi_smi_t intf = user->intf;
  968. struct cmd_rcvr *rcvr;
  969. struct cmd_rcvr *rcvrs = NULL;
  970. int i, rv = -ENOENT;
  971. mutex_lock(&intf->cmd_rcvrs_mutex);
  972. for (i = 0; i < IPMI_NUM_CHANNELS; i++) {
  973. if (((1 << i) & chans) == 0)
  974. continue;
  975. rcvr = find_cmd_rcvr(intf, netfn, cmd, i);
  976. if (rcvr == NULL)
  977. continue;
  978. if (rcvr->user == user) {
  979. rv = 0;
  980. rcvr->chans &= ~chans;
  981. if (rcvr->chans == 0) {
  982. list_del_rcu(&rcvr->link);
  983. rcvr->next = rcvrs;
  984. rcvrs = rcvr;
  985. }
  986. }
  987. }
  988. mutex_unlock(&intf->cmd_rcvrs_mutex);
  989. synchronize_rcu();
  990. while (rcvrs) {
  991. rcvr = rcvrs;
  992. rcvrs = rcvr->next;
  993. kfree(rcvr);
  994. }
  995. return rv;
  996. }
  997. void ipmi_user_set_run_to_completion(ipmi_user_t user, int val)
  998. {
  999. ipmi_smi_t intf = user->intf;
  1000. if (intf->handlers)
  1001. intf->handlers->set_run_to_completion(intf->send_info, val);
  1002. }
  1003. static unsigned char
  1004. ipmb_checksum(unsigned char *data, int size)
  1005. {
  1006. unsigned char csum = 0;
  1007. for (; size > 0; size--, data++)
  1008. csum += *data;
  1009. return -csum;
  1010. }
  1011. static inline void format_ipmb_msg(struct ipmi_smi_msg *smi_msg,
  1012. struct kernel_ipmi_msg *msg,
  1013. struct ipmi_ipmb_addr *ipmb_addr,
  1014. long msgid,
  1015. unsigned char ipmb_seq,
  1016. int broadcast,
  1017. unsigned char source_address,
  1018. unsigned char source_lun)
  1019. {
  1020. int i = broadcast;
  1021. /* Format the IPMB header data. */
  1022. smi_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
  1023. smi_msg->data[1] = IPMI_SEND_MSG_CMD;
  1024. smi_msg->data[2] = ipmb_addr->channel;
  1025. if (broadcast)
  1026. smi_msg->data[3] = 0;
  1027. smi_msg->data[i+3] = ipmb_addr->slave_addr;
  1028. smi_msg->data[i+4] = (msg->netfn << 2) | (ipmb_addr->lun & 0x3);
  1029. smi_msg->data[i+5] = ipmb_checksum(&(smi_msg->data[i+3]), 2);
  1030. smi_msg->data[i+6] = source_address;
  1031. smi_msg->data[i+7] = (ipmb_seq << 2) | source_lun;
  1032. smi_msg->data[i+8] = msg->cmd;
  1033. /* Now tack on the data to the message. */
  1034. if (msg->data_len > 0)
  1035. memcpy(&(smi_msg->data[i+9]), msg->data,
  1036. msg->data_len);
  1037. smi_msg->data_size = msg->data_len + 9;
  1038. /* Now calculate the checksum and tack it on. */
  1039. smi_msg->data[i+smi_msg->data_size]
  1040. = ipmb_checksum(&(smi_msg->data[i+6]),
  1041. smi_msg->data_size-6);
  1042. /* Add on the checksum size and the offset from the
  1043. broadcast. */
  1044. smi_msg->data_size += 1 + i;
  1045. smi_msg->msgid = msgid;
  1046. }
  1047. static inline void format_lan_msg(struct ipmi_smi_msg *smi_msg,
  1048. struct kernel_ipmi_msg *msg,
  1049. struct ipmi_lan_addr *lan_addr,
  1050. long msgid,
  1051. unsigned char ipmb_seq,
  1052. unsigned char source_lun)
  1053. {
  1054. /* Format the IPMB header data. */
  1055. smi_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
  1056. smi_msg->data[1] = IPMI_SEND_MSG_CMD;
  1057. smi_msg->data[2] = lan_addr->channel;
  1058. smi_msg->data[3] = lan_addr->session_handle;
  1059. smi_msg->data[4] = lan_addr->remote_SWID;
  1060. smi_msg->data[5] = (msg->netfn << 2) | (lan_addr->lun & 0x3);
  1061. smi_msg->data[6] = ipmb_checksum(&(smi_msg->data[4]), 2);
  1062. smi_msg->data[7] = lan_addr->local_SWID;
  1063. smi_msg->data[8] = (ipmb_seq << 2) | source_lun;
  1064. smi_msg->data[9] = msg->cmd;
  1065. /* Now tack on the data to the message. */
  1066. if (msg->data_len > 0)
  1067. memcpy(&(smi_msg->data[10]), msg->data,
  1068. msg->data_len);
  1069. smi_msg->data_size = msg->data_len + 10;
  1070. /* Now calculate the checksum and tack it on. */
  1071. smi_msg->data[smi_msg->data_size]
  1072. = ipmb_checksum(&(smi_msg->data[7]),
  1073. smi_msg->data_size-7);
  1074. /* Add on the checksum size and the offset from the
  1075. broadcast. */
  1076. smi_msg->data_size += 1;
  1077. smi_msg->msgid = msgid;
  1078. }
  1079. /* Separate from ipmi_request so that the user does not have to be
  1080. supplied in certain circumstances (mainly at panic time). If
  1081. messages are supplied, they will be freed, even if an error
  1082. occurs. */
  1083. static int i_ipmi_request(ipmi_user_t user,
  1084. ipmi_smi_t intf,
  1085. struct ipmi_addr *addr,
  1086. long msgid,
  1087. struct kernel_ipmi_msg *msg,
  1088. void *user_msg_data,
  1089. void *supplied_smi,
  1090. struct ipmi_recv_msg *supplied_recv,
  1091. int priority,
  1092. unsigned char source_address,
  1093. unsigned char source_lun,
  1094. int retries,
  1095. unsigned int retry_time_ms)
  1096. {
  1097. int rv = 0;
  1098. struct ipmi_smi_msg *smi_msg;
  1099. struct ipmi_recv_msg *recv_msg;
  1100. unsigned long flags;
  1101. struct ipmi_smi_handlers *handlers;
  1102. if (supplied_recv) {
  1103. recv_msg = supplied_recv;
  1104. } else {
  1105. recv_msg = ipmi_alloc_recv_msg();
  1106. if (recv_msg == NULL) {
  1107. return -ENOMEM;
  1108. }
  1109. }
  1110. recv_msg->user_msg_data = user_msg_data;
  1111. if (supplied_smi) {
  1112. smi_msg = (struct ipmi_smi_msg *) supplied_smi;
  1113. } else {
  1114. smi_msg = ipmi_alloc_smi_msg();
  1115. if (smi_msg == NULL) {
  1116. ipmi_free_recv_msg(recv_msg);
  1117. return -ENOMEM;
  1118. }
  1119. }
  1120. rcu_read_lock();
  1121. handlers = intf->handlers;
  1122. if (!handlers) {
  1123. rv = -ENODEV;
  1124. goto out_err;
  1125. }
  1126. recv_msg->user = user;
  1127. if (user)
  1128. kref_get(&user->refcount);
  1129. recv_msg->msgid = msgid;
  1130. /* Store the message to send in the receive message so timeout
  1131. responses can get the proper response data. */
  1132. recv_msg->msg = *msg;
  1133. if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) {
  1134. struct ipmi_system_interface_addr *smi_addr;
  1135. if (msg->netfn & 1) {
  1136. /* Responses are not allowed to the SMI. */
  1137. rv = -EINVAL;
  1138. goto out_err;
  1139. }
  1140. smi_addr = (struct ipmi_system_interface_addr *) addr;
  1141. if (smi_addr->lun > 3) {
  1142. spin_lock_irqsave(&intf->counter_lock, flags);
  1143. intf->sent_invalid_commands++;
  1144. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1145. rv = -EINVAL;
  1146. goto out_err;
  1147. }
  1148. memcpy(&recv_msg->addr, smi_addr, sizeof(*smi_addr));
  1149. if ((msg->netfn == IPMI_NETFN_APP_REQUEST)
  1150. && ((msg->cmd == IPMI_SEND_MSG_CMD)
  1151. || (msg->cmd == IPMI_GET_MSG_CMD)
  1152. || (msg->cmd == IPMI_READ_EVENT_MSG_BUFFER_CMD)))
  1153. {
  1154. /* We don't let the user do these, since we manage
  1155. the sequence numbers. */
  1156. spin_lock_irqsave(&intf->counter_lock, flags);
  1157. intf->sent_invalid_commands++;
  1158. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1159. rv = -EINVAL;
  1160. goto out_err;
  1161. }
  1162. if (((msg->netfn == IPMI_NETFN_APP_REQUEST)
  1163. && ((msg->cmd == IPMI_COLD_RESET_CMD)
  1164. || (msg->cmd == IPMI_WARM_RESET_CMD)))
  1165. || (msg->netfn == IPMI_NETFN_FIRMWARE_REQUEST))
  1166. {
  1167. spin_lock_irqsave(&intf->maintenance_mode_lock, flags);
  1168. intf->auto_maintenance_timeout
  1169. = IPMI_MAINTENANCE_MODE_TIMEOUT;
  1170. if (!intf->maintenance_mode
  1171. && !intf->maintenance_mode_enable)
  1172. {
  1173. intf->maintenance_mode_enable = 1;
  1174. maintenance_mode_update(intf);
  1175. }
  1176. spin_unlock_irqrestore(&intf->maintenance_mode_lock,
  1177. flags);
  1178. }
  1179. if ((msg->data_len + 2) > IPMI_MAX_MSG_LENGTH) {
  1180. spin_lock_irqsave(&intf->counter_lock, flags);
  1181. intf->sent_invalid_commands++;
  1182. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1183. rv = -EMSGSIZE;
  1184. goto out_err;
  1185. }
  1186. smi_msg->data[0] = (msg->netfn << 2) | (smi_addr->lun & 0x3);
  1187. smi_msg->data[1] = msg->cmd;
  1188. smi_msg->msgid = msgid;
  1189. smi_msg->user_data = recv_msg;
  1190. if (msg->data_len > 0)
  1191. memcpy(&(smi_msg->data[2]), msg->data, msg->data_len);
  1192. smi_msg->data_size = msg->data_len + 2;
  1193. spin_lock_irqsave(&intf->counter_lock, flags);
  1194. intf->sent_local_commands++;
  1195. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1196. } else if ((addr->addr_type == IPMI_IPMB_ADDR_TYPE)
  1197. || (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE))
  1198. {
  1199. struct ipmi_ipmb_addr *ipmb_addr;
  1200. unsigned char ipmb_seq;
  1201. long seqid;
  1202. int broadcast = 0;
  1203. if (addr->channel >= IPMI_MAX_CHANNELS) {
  1204. spin_lock_irqsave(&intf->counter_lock, flags);
  1205. intf->sent_invalid_commands++;
  1206. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1207. rv = -EINVAL;
  1208. goto out_err;
  1209. }
  1210. if (intf->channels[addr->channel].medium
  1211. != IPMI_CHANNEL_MEDIUM_IPMB)
  1212. {
  1213. spin_lock_irqsave(&intf->counter_lock, flags);
  1214. intf->sent_invalid_commands++;
  1215. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1216. rv = -EINVAL;
  1217. goto out_err;
  1218. }
  1219. if (retries < 0) {
  1220. if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE)
  1221. retries = 0; /* Don't retry broadcasts. */
  1222. else
  1223. retries = 4;
  1224. }
  1225. if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE) {
  1226. /* Broadcasts add a zero at the beginning of the
  1227. message, but otherwise is the same as an IPMB
  1228. address. */
  1229. addr->addr_type = IPMI_IPMB_ADDR_TYPE;
  1230. broadcast = 1;
  1231. }
  1232. /* Default to 1 second retries. */
  1233. if (retry_time_ms == 0)
  1234. retry_time_ms = 1000;
  1235. /* 9 for the header and 1 for the checksum, plus
  1236. possibly one for the broadcast. */
  1237. if ((msg->data_len + 10 + broadcast) > IPMI_MAX_MSG_LENGTH) {
  1238. spin_lock_irqsave(&intf->counter_lock, flags);
  1239. intf->sent_invalid_commands++;
  1240. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1241. rv = -EMSGSIZE;
  1242. goto out_err;
  1243. }
  1244. ipmb_addr = (struct ipmi_ipmb_addr *) addr;
  1245. if (ipmb_addr->lun > 3) {
  1246. spin_lock_irqsave(&intf->counter_lock, flags);
  1247. intf->sent_invalid_commands++;
  1248. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1249. rv = -EINVAL;
  1250. goto out_err;
  1251. }
  1252. memcpy(&recv_msg->addr, ipmb_addr, sizeof(*ipmb_addr));
  1253. if (recv_msg->msg.netfn & 0x1) {
  1254. /* It's a response, so use the user's sequence
  1255. from msgid. */
  1256. spin_lock_irqsave(&intf->counter_lock, flags);
  1257. intf->sent_ipmb_responses++;
  1258. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1259. format_ipmb_msg(smi_msg, msg, ipmb_addr, msgid,
  1260. msgid, broadcast,
  1261. source_address, source_lun);
  1262. /* Save the receive message so we can use it
  1263. to deliver the response. */
  1264. smi_msg->user_data = recv_msg;
  1265. } else {
  1266. /* It's a command, so get a sequence for it. */
  1267. spin_lock_irqsave(&(intf->seq_lock), flags);
  1268. spin_lock(&intf->counter_lock);
  1269. intf->sent_ipmb_commands++;
  1270. spin_unlock(&intf->counter_lock);
  1271. /* Create a sequence number with a 1 second
  1272. timeout and 4 retries. */
  1273. rv = intf_next_seq(intf,
  1274. recv_msg,
  1275. retry_time_ms,
  1276. retries,
  1277. broadcast,
  1278. &ipmb_seq,
  1279. &seqid);
  1280. if (rv) {
  1281. /* We have used up all the sequence numbers,
  1282. probably, so abort. */
  1283. spin_unlock_irqrestore(&(intf->seq_lock),
  1284. flags);
  1285. goto out_err;
  1286. }
  1287. /* Store the sequence number in the message,
  1288. so that when the send message response
  1289. comes back we can start the timer. */
  1290. format_ipmb_msg(smi_msg, msg, ipmb_addr,
  1291. STORE_SEQ_IN_MSGID(ipmb_seq, seqid),
  1292. ipmb_seq, broadcast,
  1293. source_address, source_lun);
  1294. /* Copy the message into the recv message data, so we
  1295. can retransmit it later if necessary. */
  1296. memcpy(recv_msg->msg_data, smi_msg->data,
  1297. smi_msg->data_size);
  1298. recv_msg->msg.data = recv_msg->msg_data;
  1299. recv_msg->msg.data_len = smi_msg->data_size;
  1300. /* We don't unlock until here, because we need
  1301. to copy the completed message into the
  1302. recv_msg before we release the lock.
  1303. Otherwise, race conditions may bite us. I
  1304. know that's pretty paranoid, but I prefer
  1305. to be correct. */
  1306. spin_unlock_irqrestore(&(intf->seq_lock), flags);
  1307. }
  1308. } else if (addr->addr_type == IPMI_LAN_ADDR_TYPE) {
  1309. struct ipmi_lan_addr *lan_addr;
  1310. unsigned char ipmb_seq;
  1311. long seqid;
  1312. if (addr->channel >= IPMI_MAX_CHANNELS) {
  1313. spin_lock_irqsave(&intf->counter_lock, flags);
  1314. intf->sent_invalid_commands++;
  1315. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1316. rv = -EINVAL;
  1317. goto out_err;
  1318. }
  1319. if ((intf->channels[addr->channel].medium
  1320. != IPMI_CHANNEL_MEDIUM_8023LAN)
  1321. && (intf->channels[addr->channel].medium
  1322. != IPMI_CHANNEL_MEDIUM_ASYNC))
  1323. {
  1324. spin_lock_irqsave(&intf->counter_lock, flags);
  1325. intf->sent_invalid_commands++;
  1326. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1327. rv = -EINVAL;
  1328. goto out_err;
  1329. }
  1330. retries = 4;
  1331. /* Default to 1 second retries. */
  1332. if (retry_time_ms == 0)
  1333. retry_time_ms = 1000;
  1334. /* 11 for the header and 1 for the checksum. */
  1335. if ((msg->data_len + 12) > IPMI_MAX_MSG_LENGTH) {
  1336. spin_lock_irqsave(&intf->counter_lock, flags);
  1337. intf->sent_invalid_commands++;
  1338. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1339. rv = -EMSGSIZE;
  1340. goto out_err;
  1341. }
  1342. lan_addr = (struct ipmi_lan_addr *) addr;
  1343. if (lan_addr->lun > 3) {
  1344. spin_lock_irqsave(&intf->counter_lock, flags);
  1345. intf->sent_invalid_commands++;
  1346. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1347. rv = -EINVAL;
  1348. goto out_err;
  1349. }
  1350. memcpy(&recv_msg->addr, lan_addr, sizeof(*lan_addr));
  1351. if (recv_msg->msg.netfn & 0x1) {
  1352. /* It's a response, so use the user's sequence
  1353. from msgid. */
  1354. spin_lock_irqsave(&intf->counter_lock, flags);
  1355. intf->sent_lan_responses++;
  1356. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1357. format_lan_msg(smi_msg, msg, lan_addr, msgid,
  1358. msgid, source_lun);
  1359. /* Save the receive message so we can use it
  1360. to deliver the response. */
  1361. smi_msg->user_data = recv_msg;
  1362. } else {
  1363. /* It's a command, so get a sequence for it. */
  1364. spin_lock_irqsave(&(intf->seq_lock), flags);
  1365. spin_lock(&intf->counter_lock);
  1366. intf->sent_lan_commands++;
  1367. spin_unlock(&intf->counter_lock);
  1368. /* Create a sequence number with a 1 second
  1369. timeout and 4 retries. */
  1370. rv = intf_next_seq(intf,
  1371. recv_msg,
  1372. retry_time_ms,
  1373. retries,
  1374. 0,
  1375. &ipmb_seq,
  1376. &seqid);
  1377. if (rv) {
  1378. /* We have used up all the sequence numbers,
  1379. probably, so abort. */
  1380. spin_unlock_irqrestore(&(intf->seq_lock),
  1381. flags);
  1382. goto out_err;
  1383. }
  1384. /* Store the sequence number in the message,
  1385. so that when the send message response
  1386. comes back we can start the timer. */
  1387. format_lan_msg(smi_msg, msg, lan_addr,
  1388. STORE_SEQ_IN_MSGID(ipmb_seq, seqid),
  1389. ipmb_seq, source_lun);
  1390. /* Copy the message into the recv message data, so we
  1391. can retransmit it later if necessary. */
  1392. memcpy(recv_msg->msg_data, smi_msg->data,
  1393. smi_msg->data_size);
  1394. recv_msg->msg.data = recv_msg->msg_data;
  1395. recv_msg->msg.data_len = smi_msg->data_size;
  1396. /* We don't unlock until here, because we need
  1397. to copy the completed message into the
  1398. recv_msg before we release the lock.
  1399. Otherwise, race conditions may bite us. I
  1400. know that's pretty paranoid, but I prefer
  1401. to be correct. */
  1402. spin_unlock_irqrestore(&(intf->seq_lock), flags);
  1403. }
  1404. } else {
  1405. /* Unknown address type. */
  1406. spin_lock_irqsave(&intf->counter_lock, flags);
  1407. intf->sent_invalid_commands++;
  1408. spin_unlock_irqrestore(&intf->counter_lock, flags);
  1409. rv = -EINVAL;
  1410. goto out_err;
  1411. }
  1412. #ifdef DEBUG_MSGING
  1413. {
  1414. int m;
  1415. for (m = 0; m < smi_msg->data_size; m++)
  1416. printk(" %2.2x", smi_msg->data[m]);
  1417. printk("\n");
  1418. }
  1419. #endif
  1420. handlers->sender(intf->send_info, smi_msg, priority);
  1421. rcu_read_unlock();
  1422. return 0;
  1423. out_err:
  1424. rcu_read_unlock();
  1425. ipmi_free_smi_msg(smi_msg);
  1426. ipmi_free_recv_msg(recv_msg);
  1427. return rv;
  1428. }
  1429. static int check_addr(ipmi_smi_t intf,
  1430. struct ipmi_addr *addr,
  1431. unsigned char *saddr,
  1432. unsigned char *lun)
  1433. {
  1434. if (addr->channel >= IPMI_MAX_CHANNELS)
  1435. return -EINVAL;
  1436. *lun = intf->channels[addr->channel].lun;
  1437. *saddr = intf->channels[addr->channel].address;
  1438. return 0;
  1439. }
  1440. int ipmi_request_settime(ipmi_user_t user,
  1441. struct ipmi_addr *addr,
  1442. long msgid,
  1443. struct kernel_ipmi_msg *msg,
  1444. void *user_msg_data,
  1445. int priority,
  1446. int retries,
  1447. unsigned int retry_time_ms)
  1448. {
  1449. unsigned char saddr, lun;
  1450. int rv;
  1451. if (!user)
  1452. return -EINVAL;
  1453. rv = check_addr(user->intf, addr, &saddr, &lun);
  1454. if (rv)
  1455. return rv;
  1456. return i_ipmi_request(user,
  1457. user->intf,
  1458. addr,
  1459. msgid,
  1460. msg,
  1461. user_msg_data,
  1462. NULL, NULL,
  1463. priority,
  1464. saddr,
  1465. lun,
  1466. retries,
  1467. retry_time_ms);
  1468. }
  1469. int ipmi_request_supply_msgs(ipmi_user_t user,
  1470. struct ipmi_addr *addr,
  1471. long msgid,
  1472. struct kernel_ipmi_msg *msg,
  1473. void *user_msg_data,
  1474. void *supplied_smi,
  1475. struct ipmi_recv_msg *supplied_recv,
  1476. int priority)
  1477. {
  1478. unsigned char saddr, lun;
  1479. int rv;
  1480. if (!user)
  1481. return -EINVAL;
  1482. rv = check_addr(user->intf, addr, &saddr, &lun);
  1483. if (rv)
  1484. return rv;
  1485. return i_ipmi_request(user,
  1486. user->intf,
  1487. addr,
  1488. msgid,
  1489. msg,
  1490. user_msg_data,
  1491. supplied_smi,
  1492. supplied_recv,
  1493. priority,
  1494. saddr,
  1495. lun,
  1496. -1, 0);
  1497. }
  1498. #ifdef CONFIG_PROC_FS
  1499. static int ipmb_file_read_proc(char *page, char **start, off_t off,
  1500. int count, int *eof, void *data)
  1501. {
  1502. char *out = (char *) page;
  1503. ipmi_smi_t intf = data;
  1504. int i;
  1505. int rv = 0;
  1506. for (i = 0; i < IPMI_MAX_CHANNELS; i++)
  1507. rv += sprintf(out+rv, "%x ", intf->channels[i].address);
  1508. out[rv-1] = '\n'; /* Replace the final space with a newline */
  1509. out[rv] = '\0';
  1510. rv++;
  1511. return rv;
  1512. }
  1513. static int version_file_read_proc(char *page, char **start, off_t off,
  1514. int count, int *eof, void *data)
  1515. {
  1516. char *out = (char *) page;
  1517. ipmi_smi_t intf = data;
  1518. return sprintf(out, "%d.%d\n",
  1519. ipmi_version_major(&intf->bmc->id),
  1520. ipmi_version_minor(&intf->bmc->id));
  1521. }
  1522. static int stat_file_read_proc(char *page, char **start, off_t off,
  1523. int count, int *eof, void *data)
  1524. {
  1525. char *out = (char *) page;
  1526. ipmi_smi_t intf = data;
  1527. out += sprintf(out, "sent_invalid_commands: %d\n",
  1528. intf->sent_invalid_commands);
  1529. out += sprintf(out, "sent_local_commands: %d\n",
  1530. intf->sent_local_commands);
  1531. out += sprintf(out, "handled_local_responses: %d\n",
  1532. intf->handled_local_responses);
  1533. out += sprintf(out, "unhandled_local_responses: %d\n",
  1534. intf->unhandled_local_responses);
  1535. out += sprintf(out, "sent_ipmb_commands: %d\n",
  1536. intf->sent_ipmb_commands);
  1537. out += sprintf(out, "sent_ipmb_command_errs: %d\n",
  1538. intf->sent_ipmb_command_errs);
  1539. out += sprintf(out, "retransmitted_ipmb_commands: %d\n",
  1540. intf->retransmitted_ipmb_commands);
  1541. out += sprintf(out, "timed_out_ipmb_commands: %d\n",
  1542. intf->timed_out_ipmb_commands);
  1543. out += sprintf(out, "timed_out_ipmb_broadcasts: %d\n",
  1544. intf->timed_out_ipmb_broadcasts);
  1545. out += sprintf(out, "sent_ipmb_responses: %d\n",
  1546. intf->sent_ipmb_responses);
  1547. out += sprintf(out, "handled_ipmb_responses: %d\n",
  1548. intf->handled_ipmb_responses);
  1549. out += sprintf(out, "invalid_ipmb_responses: %d\n",
  1550. intf->invalid_ipmb_responses);
  1551. out += sprintf(out, "unhandled_ipmb_responses: %d\n",
  1552. intf->unhandled_ipmb_responses);
  1553. out += sprintf(out, "sent_lan_commands: %d\n",
  1554. intf->sent_lan_commands);
  1555. out += sprintf(out, "sent_lan_command_errs: %d\n",
  1556. intf->sent_lan_command_errs);
  1557. out += sprintf(out, "retransmitted_lan_commands: %d\n",
  1558. intf->retransmitted_lan_commands);
  1559. out += sprintf(out, "timed_out_lan_commands: %d\n",
  1560. intf->timed_out_lan_commands);
  1561. out += sprintf(out, "sent_lan_responses: %d\n",
  1562. intf->sent_lan_responses);
  1563. out += sprintf(out, "handled_lan_responses: %d\n",
  1564. intf->handled_lan_responses);
  1565. out += sprintf(out, "invalid_lan_responses: %d\n",
  1566. intf->invalid_lan_responses);
  1567. out += sprintf(out, "unhandled_lan_responses: %d\n",
  1568. intf->unhandled_lan_responses);
  1569. out += sprintf(out, "handled_commands: %d\n",
  1570. intf->handled_commands);
  1571. out += sprintf(out, "invalid_commands: %d\n",
  1572. intf->invalid_commands);
  1573. out += sprintf(out, "unhandled_commands: %d\n",
  1574. intf->unhandled_commands);
  1575. out += sprintf(out, "invalid_events: %d\n",
  1576. intf->invalid_events);
  1577. out += sprintf(out, "events: %d\n",
  1578. intf->events);
  1579. return (out - ((char *) page));
  1580. }
  1581. #endif /* CONFIG_PROC_FS */
  1582. int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
  1583. read_proc_t *read_proc, write_proc_t *write_proc,
  1584. void *data, struct module *owner)
  1585. {
  1586. int rv = 0;
  1587. #ifdef CONFIG_PROC_FS
  1588. struct proc_dir_entry *file;
  1589. struct ipmi_proc_entry *entry;
  1590. /* Create a list element. */
  1591. entry = kmalloc(sizeof(*entry), GFP_KERNEL);
  1592. if (!entry)
  1593. return -ENOMEM;
  1594. entry->name = kmalloc(strlen(name)+1, GFP_KERNEL);
  1595. if (!entry->name) {
  1596. kfree(entry);
  1597. return -ENOMEM;
  1598. }
  1599. strcpy(entry->name, name);
  1600. file = create_proc_entry(name, 0, smi->proc_dir);
  1601. if (!file) {
  1602. kfree(entry->name);
  1603. kfree(entry);
  1604. rv = -ENOMEM;
  1605. } else {
  1606. file->data = data;
  1607. file->read_proc = read_proc;
  1608. file->write_proc = write_proc;
  1609. file->owner = owner;
  1610. mutex_lock(&smi->proc_entry_lock);
  1611. /* Stick it on the list. */
  1612. entry->next = smi->proc_entries;
  1613. smi->proc_entries = entry;
  1614. mutex_unlock(&smi->proc_entry_lock);
  1615. }
  1616. #endif /* CONFIG_PROC_FS */
  1617. return rv;
  1618. }
  1619. static int add_proc_entries(ipmi_smi_t smi, int num)
  1620. {
  1621. int rv = 0;
  1622. #ifdef CONFIG_PROC_FS
  1623. sprintf(smi->proc_dir_name, "%d", num);
  1624. smi->proc_dir = proc_mkdir(smi->proc_dir_name, proc_ipmi_root);
  1625. if (!smi->proc_dir)
  1626. rv = -ENOMEM;
  1627. else {
  1628. smi->proc_dir->owner = THIS_MODULE;
  1629. }
  1630. if (rv == 0)
  1631. rv = ipmi_smi_add_proc_entry(smi, "stats",
  1632. stat_file_read_proc, NULL,
  1633. smi, THIS_MODULE);
  1634. if (rv == 0)
  1635. rv = ipmi_smi_add_proc_entry(smi, "ipmb",
  1636. ipmb_file_read_proc, NULL,
  1637. smi, THIS_MODULE);
  1638. if (rv == 0)
  1639. rv = ipmi_smi_add_proc_entry(smi, "version",
  1640. version_file_read_proc, NULL,
  1641. smi, THIS_MODULE);
  1642. #endif /* CONFIG_PROC_FS */
  1643. return rv;
  1644. }
  1645. static void remove_proc_entries(ipmi_smi_t smi)
  1646. {
  1647. #ifdef CONFIG_PROC_FS
  1648. struct ipmi_proc_entry *entry;
  1649. mutex_lock(&smi->proc_entry_lock);
  1650. while (smi->proc_entries) {
  1651. entry = smi->proc_entries;
  1652. smi->proc_entries = entry->next;
  1653. remove_proc_entry(entry->name, smi->proc_dir);
  1654. kfree(entry->name);
  1655. kfree(entry);
  1656. }
  1657. mutex_unlock(&smi->proc_entry_lock);
  1658. remove_proc_entry(smi->proc_dir_name, proc_ipmi_root);
  1659. #endif /* CONFIG_PROC_FS */
  1660. }
  1661. static int __find_bmc_guid(struct device *dev, void *data)
  1662. {
  1663. unsigned char *id = data;
  1664. struct bmc_device *bmc = dev_get_drvdata(dev);
  1665. return memcmp(bmc->guid, id, 16) == 0;
  1666. }
  1667. static struct bmc_device *ipmi_find_bmc_guid(struct device_driver *drv,
  1668. unsigned char *guid)
  1669. {
  1670. struct device *dev;
  1671. dev = driver_find_device(drv, NULL, guid, __find_bmc_guid);
  1672. if (dev)
  1673. return dev_get_drvdata(dev);
  1674. else
  1675. return NULL;
  1676. }
  1677. struct prod_dev_id {
  1678. unsigned int product_id;
  1679. unsigned char device_id;
  1680. };
  1681. static int __find_bmc_prod_dev_id(struct device *dev, void *data)
  1682. {
  1683. struct prod_dev_id *id = data;
  1684. struct bmc_device *bmc = dev_get_drvdata(dev);
  1685. return (bmc->id.product_id == id->product_id
  1686. && bmc->id.device_id == id->device_id);
  1687. }
  1688. static struct bmc_device *ipmi_find_bmc_prod_dev_id(
  1689. struct device_driver *drv,
  1690. unsigned int product_id, unsigned char device_id)
  1691. {
  1692. struct prod_dev_id id = {
  1693. .product_id = product_id,
  1694. .device_id = device_id,
  1695. };
  1696. struct device *dev;
  1697. dev = driver_find_device(drv, NULL, &id, __find_bmc_prod_dev_id);
  1698. if (dev)
  1699. return dev_get_drvdata(dev);
  1700. else
  1701. return NULL;
  1702. }
  1703. static ssize_t device_id_show(struct device *dev,
  1704. struct device_attribute *attr,
  1705. char *buf)
  1706. {
  1707. struct bmc_device *bmc = dev_get_drvdata(dev);
  1708. return snprintf(buf, 10, "%u\n", bmc->id.device_id);
  1709. }
  1710. static ssize_t provides_dev_sdrs_show(struct device *dev,
  1711. struct device_attribute *attr,
  1712. char *buf)
  1713. {
  1714. struct bmc_device *bmc = dev_get_drvdata(dev);
  1715. return snprintf(buf, 10, "%u\n",
  1716. (bmc->id.device_revision & 0x80) >> 7);
  1717. }
  1718. static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
  1719. char *buf)
  1720. {
  1721. struct bmc_device *bmc = dev_get_drvdata(dev);
  1722. return snprintf(buf, 20, "%u\n",
  1723. bmc->id.device_revision & 0x0F);
  1724. }
  1725. static ssize_t firmware_rev_show(struct device *dev,
  1726. struct device_attribute *attr,
  1727. char *buf)
  1728. {
  1729. struct bmc_device *bmc = dev_get_drvdata(dev);
  1730. return snprintf(buf, 20, "%u.%x\n", bmc->id.firmware_revision_1,
  1731. bmc->id.firmware_revision_2);
  1732. }
  1733. static ssize_t ipmi_version_show(struct device *dev,
  1734. struct device_attribute *attr,
  1735. char *buf)
  1736. {
  1737. struct bmc_device *bmc = dev_get_drvdata(dev);
  1738. return snprintf(buf, 20, "%u.%u\n",
  1739. ipmi_version_major(&bmc->id),
  1740. ipmi_version_minor(&bmc->id));
  1741. }
  1742. static ssize_t add_dev_support_show(struct device *dev,
  1743. struct device_attribute *attr,
  1744. char *buf)
  1745. {
  1746. struct bmc_device *bmc = dev_get_drvdata(dev);
  1747. return snprintf(buf, 10, "0x%02x\n",
  1748. bmc->id.additional_device_support);
  1749. }
  1750. static ssize_t manufacturer_id_show(struct device *dev,
  1751. struct device_attribute *attr,
  1752. char *buf)
  1753. {
  1754. struct bmc_device *bmc = dev_get_drvdata(dev);
  1755. return snprintf(buf, 20, "0x%6.6x\n", bmc->id.manufacturer_id);
  1756. }
  1757. static ssize_t product_id_show(struct device *dev,
  1758. struct device_attribute *attr,
  1759. char *buf)
  1760. {
  1761. struct bmc_device *bmc = dev_get_drvdata(dev);
  1762. return snprintf(buf, 10, "0x%4.4x\n", bmc->id.product_id);
  1763. }
  1764. static ssize_t aux_firmware_rev_show(struct device *dev,
  1765. struct device_attribute *attr,
  1766. char *buf)
  1767. {
  1768. struct bmc_device *bmc = dev_get_drvdata(dev);
  1769. return snprintf(buf, 21, "0x%02x 0x%02x 0x%02x 0x%02x\n",
  1770. bmc->id.aux_firmware_revision[3],
  1771. bmc->id.aux_firmware_revision[2],
  1772. bmc->id.aux_firmware_revision[1],
  1773. bmc->id.aux_firmware_revision[0]);
  1774. }
  1775. static ssize_t guid_show(struct device *dev, struct device_attribute *attr,
  1776. char *buf)
  1777. {
  1778. struct bmc_device *bmc = dev_get_drvdata(dev);
  1779. return snprintf(buf, 100, "%Lx%Lx\n",
  1780. (long long) bmc->guid[0],
  1781. (long long) bmc->guid[8]);
  1782. }
  1783. static void remove_files(struct bmc_device *bmc)
  1784. {
  1785. if (!bmc->dev)
  1786. return;
  1787. device_remove_file(&bmc->dev->dev,
  1788. &bmc->device_id_attr);
  1789. device_remove_file(&bmc->dev->dev,
  1790. &bmc->provides_dev_sdrs_attr);
  1791. device_remove_file(&bmc->dev->dev,
  1792. &bmc->revision_attr);
  1793. device_remove_file(&bmc->dev->dev,
  1794. &bmc->firmware_rev_attr);
  1795. device_remove_file(&bmc->dev->dev,
  1796. &bmc->version_attr);
  1797. device_remove_file(&bmc->dev->dev,
  1798. &bmc->add_dev_support_attr);
  1799. device_remove_file(&bmc->dev->dev,
  1800. &bmc->manufacturer_id_attr);
  1801. device_remove_file(&bmc->dev->dev,
  1802. &bmc->product_id_attr);
  1803. if (bmc->id.aux_firmware_revision_set)
  1804. device_remove_file(&bmc->dev->dev,
  1805. &bmc->aux_firmware_rev_attr);
  1806. if (bmc->guid_set)
  1807. device_remove_file(&bmc->dev->dev,
  1808. &bmc->guid_attr);
  1809. }
  1810. static void
  1811. cleanup_bmc_device(struct kref *ref)
  1812. {
  1813. struct bmc_device *bmc;
  1814. bmc = container_of(ref, struct bmc_device, refcount);
  1815. remove_files(bmc);
  1816. platform_device_unregister(bmc->dev);
  1817. kfree(bmc);
  1818. }
  1819. static void ipmi_bmc_unregister(ipmi_smi_t intf)
  1820. {
  1821. struct bmc_device *bmc = intf->bmc;
  1822. if (intf->sysfs_name) {
  1823. sysfs_remove_link(&intf->si_dev->kobj, intf->sysfs_name);
  1824. kfree(intf->sysfs_name);
  1825. intf->sysfs_name = NULL;
  1826. }
  1827. if (intf->my_dev_name) {
  1828. sysfs_remove_link(&bmc->dev->dev.kobj, intf->my_dev_name);
  1829. kfree(intf->my_dev_name);
  1830. intf->my_dev_name = NULL;
  1831. }
  1832. mutex_lock(&ipmidriver_mutex);
  1833. kref_put(&bmc->refcount, cleanup_bmc_device);
  1834. intf->bmc = NULL;
  1835. mutex_unlock(&ipmidriver_mutex);
  1836. }
  1837. static int create_files(struct bmc_device *bmc)
  1838. {
  1839. int err;
  1840. bmc->device_id_attr.attr.name = "device_id";
  1841. bmc->device_id_attr.attr.mode = S_IRUGO;
  1842. bmc->device_id_attr.show = device_id_show;
  1843. bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs";
  1844. bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO;
  1845. bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show;
  1846. bmc->revision_attr.attr.name = "revision";
  1847. bmc->revision_attr.attr.mode = S_IRUGO;
  1848. bmc->revision_attr.show = revision_show;
  1849. bmc->firmware_rev_attr.attr.name = "firmware_revision";
  1850. bmc->firmware_rev_attr.attr.mode = S_IRUGO;
  1851. bmc->firmware_rev_attr.show = firmware_rev_show;
  1852. bmc->version_attr.attr.name = "ipmi_version";
  1853. bmc->version_attr.attr.mode = S_IRUGO;
  1854. bmc->version_attr.show = ipmi_version_show;
  1855. bmc->add_dev_support_attr.attr.name = "additional_device_support";
  1856. bmc->add_dev_support_attr.attr.mode = S_IRUGO;
  1857. bmc->add_dev_support_attr.show = add_dev_support_show;
  1858. bmc->manufacturer_id_attr.attr.name = "manufacturer_id";
  1859. bmc->manufacturer_id_attr.attr.mode = S_IRUGO;
  1860. bmc->manufacturer_id_attr.show = manufacturer_id_show;
  1861. bmc->product_id_attr.attr.name = "product_id";
  1862. bmc->product_id_attr.attr.mode = S_IRUGO;
  1863. bmc->product_id_attr.show = product_id_show;
  1864. bmc->guid_attr.attr.name = "guid";
  1865. bmc->guid_attr.attr.mode = S_IRUGO;
  1866. bmc->guid_attr.show = guid_show;
  1867. bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision";
  1868. bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO;
  1869. bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show;
  1870. err = device_create_file(&bmc->dev->dev,
  1871. &bmc->device_id_attr);
  1872. if (err) goto out;
  1873. err = device_create_file(&bmc->dev->dev,
  1874. &bmc->provides_dev_sdrs_attr);
  1875. if (err) goto out_devid;
  1876. err = device_create_file(&bmc->dev->dev,
  1877. &bmc->revision_attr);
  1878. if (err) goto out_sdrs;
  1879. err = device_create_file(&bmc->dev->dev,
  1880. &bmc->firmware_rev_attr);
  1881. if (err) goto out_rev;
  1882. err = device_create_file(&bmc->dev->dev,
  1883. &bmc->version_attr);
  1884. if (err) goto out_firm;
  1885. err = device_create_file(&bmc->dev->dev,
  1886. &bmc->add_dev_support_attr);
  1887. if (err) goto out_version;
  1888. err = device_create_file(&bmc->dev->dev,
  1889. &bmc->manufacturer_id_attr);
  1890. if (err) goto out_add_dev;
  1891. err = device_create_file(&bmc->dev->dev,
  1892. &bmc->product_id_attr);
  1893. if (err) goto out_manu;
  1894. if (bmc->id.aux_firmware_revision_set) {
  1895. err = device_create_file(&bmc->dev->dev,
  1896. &bmc->aux_firmware_rev_attr);
  1897. if (err) goto out_prod_id;
  1898. }
  1899. if (bmc->guid_set) {
  1900. err = device_create_file(&bmc->dev->dev,
  1901. &bmc->guid_attr);
  1902. if (err) goto out_aux_firm;
  1903. }
  1904. return 0;
  1905. out_aux_firm:
  1906. if (bmc->id.aux_firmware_revision_set)
  1907. device_remove_file(&bmc->dev->dev,
  1908. &bmc->aux_firmware_rev_attr);
  1909. out_prod_id:
  1910. device_remove_file(&bmc->dev->dev,
  1911. &bmc->product_id_attr);
  1912. out_manu:
  1913. device_remove_file(&bmc->dev->dev,
  1914. &bmc->manufacturer_id_attr);
  1915. out_add_dev:
  1916. device_remove_file(&bmc->dev->dev,
  1917. &bmc->add_dev_support_attr);
  1918. out_version:
  1919. device_remove_file(&bmc->dev->dev,
  1920. &bmc->version_attr);
  1921. out_firm:
  1922. device_remove_file(&bmc->dev->dev,
  1923. &bmc->firmware_rev_attr);
  1924. out_rev:
  1925. device_remove_file(&bmc->dev->dev,
  1926. &bmc->revision_attr);
  1927. out_sdrs:
  1928. device_remove_file(&bmc->dev->dev,
  1929. &bmc->provides_dev_sdrs_attr);
  1930. out_devid:
  1931. device_remove_file(&bmc->dev->dev,
  1932. &bmc->device_id_attr);
  1933. out:
  1934. return err;
  1935. }
  1936. static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum,
  1937. const char *sysfs_name)
  1938. {
  1939. int rv;
  1940. struct bmc_device *bmc = intf->bmc;
  1941. struct bmc_device *old_bmc;
  1942. int size;
  1943. char dummy[1];
  1944. mutex_lock(&ipmidriver_mutex);
  1945. /*
  1946. * Try to find if there is an bmc_device struct
  1947. * representing the interfaced BMC already
  1948. */
  1949. if (bmc->guid_set)
  1950. old_bmc = ipmi_find_bmc_guid(&ipmidriver, bmc->guid);
  1951. else
  1952. old_bmc = ipmi_find_bmc_prod_dev_id(&ipmidriver,
  1953. bmc->id.product_id,
  1954. bmc->id.device_id);
  1955. /*
  1956. * If there is already an bmc_device, free the new one,
  1957. * otherwise register the new BMC device
  1958. */
  1959. if (old_bmc) {
  1960. kfree(bmc);
  1961. intf->bmc = old_bmc;
  1962. bmc = old_bmc;
  1963. kref_get(&bmc->refcount);
  1964. mutex_unlock(&ipmidriver_mutex);
  1965. printk(KERN_INFO
  1966. "ipmi: interfacing existing BMC (man_id: 0x%6.6x,"
  1967. " prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n",
  1968. bmc->id.manufacturer_id,
  1969. bmc->id.product_id,
  1970. bmc->id.device_id);
  1971. } else {
  1972. char name[14];
  1973. unsigned char orig_dev_id = bmc->id.device_id;
  1974. int warn_printed = 0;
  1975. snprintf(name, sizeof(name),
  1976. "ipmi_bmc.%4.4x", bmc->id.product_id);
  1977. while (ipmi_find_bmc_prod_dev_id(&ipmidriver,
  1978. bmc->id.product_id,
  1979. bmc->id.device_id)) {
  1980. if (!warn_printed) {
  1981. printk(KERN_WARNING PFX
  1982. "This machine has two different BMCs"
  1983. " with the same product id and device"
  1984. " id. This is an error in the"
  1985. " firmware, but incrementing the"
  1986. " device id to work around the problem."
  1987. " Prod ID = 0x%x, Dev ID = 0x%x\n",
  1988. bmc->id.product_id, bmc->id.device_id);
  1989. warn_printed = 1;
  1990. }
  1991. bmc->id.device_id++; /* Wraps at 255 */
  1992. if (bmc->id.device_id == orig_dev_id) {
  1993. printk(KERN_ERR PFX
  1994. "Out of device ids!\n");
  1995. break;
  1996. }
  1997. }
  1998. bmc->dev = platform_device_alloc(name, bmc->id.device_id);
  1999. if (!bmc->dev) {
  2000. mutex_unlock(&ipmidriver_mutex);
  2001. printk(KERN_ERR
  2002. "ipmi_msghandler:"
  2003. " Unable to allocate platform device\n");
  2004. return -ENOMEM;
  2005. }
  2006. bmc->dev->dev.driver = &ipmidriver;
  2007. dev_set_drvdata(&bmc->dev->dev, bmc);
  2008. kref_init(&bmc->refcount);
  2009. rv = platform_device_add(bmc->dev);
  2010. mutex_unlock(&ipmidriver_mutex);
  2011. if (rv) {
  2012. platform_device_put(bmc->dev);
  2013. bmc->dev = NULL;
  2014. printk(KERN_ERR
  2015. "ipmi_msghandler:"
  2016. " Unable to register bmc device: %d\n",
  2017. rv);
  2018. /* Don't go to out_err, you can only do that if
  2019. the device is registered already. */
  2020. return rv;
  2021. }
  2022. rv = create_files(bmc);
  2023. if (rv) {
  2024. mutex_lock(&ipmidriver_mutex);
  2025. platform_device_unregister(bmc->dev);
  2026. mutex_unlock(&ipmidriver_mutex);
  2027. return rv;
  2028. }
  2029. printk(KERN_INFO
  2030. "ipmi: Found new BMC (man_id: 0x%6.6x, "
  2031. " prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n",
  2032. bmc->id.manufacturer_id,
  2033. bmc->id.product_id,
  2034. bmc->id.device_id);
  2035. }
  2036. /*
  2037. * create symlink from system interface device to bmc device
  2038. * and back.
  2039. */
  2040. intf->sysfs_name = kstrdup(sysfs_name, GFP_KERNEL);
  2041. if (!intf->sysfs_name) {
  2042. rv = -ENOMEM;
  2043. printk(KERN_ERR
  2044. "ipmi_msghandler: allocate link to BMC: %d\n",
  2045. rv);
  2046. goto out_err;
  2047. }
  2048. rv = sysfs_create_link(&intf->si_dev->kobj,
  2049. &bmc->dev->dev.kobj, intf->sysfs_name);
  2050. if (rv) {
  2051. kfree(intf->sysfs_name);
  2052. intf->sysfs_name = NULL;
  2053. printk(KERN_ERR
  2054. "ipmi_msghandler: Unable to create bmc symlink: %d\n",
  2055. rv);
  2056. goto out_err;
  2057. }
  2058. size = snprintf(dummy, 0, "ipmi%d", ifnum);
  2059. intf->my_dev_name = kmalloc(size+1, GFP_KERNEL);
  2060. if (!intf->my_dev_name) {
  2061. kfree(intf->sysfs_name);
  2062. intf->sysfs_name = NULL;
  2063. rv = -ENOMEM;
  2064. printk(KERN_ERR
  2065. "ipmi_msghandler: allocate link from BMC: %d\n",
  2066. rv);
  2067. goto out_err;
  2068. }
  2069. snprintf(intf->my_dev_name, size+1, "ipmi%d", ifnum);
  2070. rv = sysfs_create_link(&bmc->dev->dev.kobj, &intf->si_dev->kobj,
  2071. intf->my_dev_name);
  2072. if (rv) {
  2073. kfree(intf->sysfs_name);
  2074. intf->sysfs_name = NULL;
  2075. kfree(intf->my_dev_name);
  2076. intf->my_dev_name = NULL;
  2077. printk(KERN_ERR
  2078. "ipmi_msghandler:"
  2079. " Unable to create symlink to bmc: %d\n",
  2080. rv);
  2081. goto out_err;
  2082. }
  2083. return 0;
  2084. out_err:
  2085. ipmi_bmc_unregister(intf);
  2086. return rv;
  2087. }
  2088. static int
  2089. send_guid_cmd(ipmi_smi_t intf, int chan)
  2090. {
  2091. struct kernel_ipmi_msg msg;
  2092. struct ipmi_system_interface_addr si;
  2093. si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  2094. si.channel = IPMI_BMC_CHANNEL;
  2095. si.lun = 0;
  2096. msg.netfn = IPMI_NETFN_APP_REQUEST;
  2097. msg.cmd = IPMI_GET_DEVICE_GUID_CMD;
  2098. msg.data = NULL;
  2099. msg.data_len = 0;
  2100. return i_ipmi_request(NULL,
  2101. intf,
  2102. (struct ipmi_addr *) &si,
  2103. 0,
  2104. &msg,
  2105. intf,
  2106. NULL,
  2107. NULL,
  2108. 0,
  2109. intf->channels[0].address,
  2110. intf->channels[0].lun,
  2111. -1, 0);
  2112. }
  2113. static void
  2114. guid_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
  2115. {
  2116. if ((msg->addr.addr_type != IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
  2117. || (msg->msg.netfn != IPMI_NETFN_APP_RESPONSE)
  2118. || (msg->msg.cmd != IPMI_GET_DEVICE_GUID_CMD))
  2119. /* Not for me */
  2120. return;
  2121. if (msg->msg.data[0] != 0) {
  2122. /* Error from getting the GUID, the BMC doesn't have one. */
  2123. intf->bmc->guid_set = 0;
  2124. goto out;
  2125. }
  2126. if (msg->msg.data_len < 17) {
  2127. intf->bmc->guid_set = 0;
  2128. printk(KERN_WARNING PFX
  2129. "guid_handler: The GUID response from the BMC was too"
  2130. " short, it was %d but should have been 17. Assuming"
  2131. " GUID is not available.\n",
  2132. msg->msg.data_len);
  2133. goto out;
  2134. }
  2135. memcpy(intf->bmc->guid, msg->msg.data, 16);
  2136. intf->bmc->guid_set = 1;
  2137. out:
  2138. wake_up(&intf->waitq);
  2139. }
  2140. static void
  2141. get_guid(ipmi_smi_t intf)
  2142. {
  2143. int rv;
  2144. intf->bmc->guid_set = 0x2;
  2145. intf->null_user_handler = guid_handler;
  2146. rv = send_guid_cmd(intf, 0);
  2147. if (rv)
  2148. /* Send failed, no GUID available. */
  2149. intf->bmc->guid_set = 0;
  2150. wait_event(intf->waitq, intf->bmc->guid_set != 2);
  2151. intf->null_user_handler = NULL;
  2152. }
  2153. static int
  2154. send_channel_info_cmd(ipmi_smi_t intf, int chan)
  2155. {
  2156. struct kernel_ipmi_msg msg;
  2157. unsigned char data[1];
  2158. struct ipmi_system_interface_addr si;
  2159. si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  2160. si.channel = IPMI_BMC_CHANNEL;
  2161. si.lun = 0;
  2162. msg.netfn = IPMI_NETFN_APP_REQUEST;
  2163. msg.cmd = IPMI_GET_CHANNEL_INFO_CMD;
  2164. msg.data = data;
  2165. msg.data_len = 1;
  2166. data[0] = chan;
  2167. return i_ipmi_request(NULL,
  2168. intf,
  2169. (struct ipmi_addr *) &si,
  2170. 0,
  2171. &msg,
  2172. intf,
  2173. NULL,
  2174. NULL,
  2175. 0,
  2176. intf->channels[0].address,
  2177. intf->channels[0].lun,
  2178. -1, 0);
  2179. }
  2180. static void
  2181. channel_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
  2182. {
  2183. int rv = 0;
  2184. int chan;
  2185. if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
  2186. && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE)
  2187. && (msg->msg.cmd == IPMI_GET_CHANNEL_INFO_CMD))
  2188. {
  2189. /* It's the one we want */
  2190. if (msg->msg.data[0] != 0) {
  2191. /* Got an error from the channel, just go on. */
  2192. if (msg->msg.data[0] == IPMI_INVALID_COMMAND_ERR) {
  2193. /* If the MC does not support this
  2194. command, that is legal. We just
  2195. assume it has one IPMB at channel
  2196. zero. */
  2197. intf->channels[0].medium
  2198. = IPMI_CHANNEL_MEDIUM_IPMB;
  2199. intf->channels[0].protocol
  2200. = IPMI_CHANNEL_PROTOCOL_IPMB;
  2201. rv = -ENOSYS;
  2202. intf->curr_channel = IPMI_MAX_CHANNELS;
  2203. wake_up(&intf->waitq);
  2204. goto out;
  2205. }
  2206. goto next_channel;
  2207. }
  2208. if (msg->msg.data_len < 4) {
  2209. /* Message not big enough, just go on. */
  2210. goto next_channel;
  2211. }
  2212. chan = intf->curr_channel;
  2213. intf->channels[chan].medium = msg->msg.data[2] & 0x7f;
  2214. intf->channels[chan].protocol = msg->msg.data[3] & 0x1f;
  2215. next_channel:
  2216. intf->curr_channel++;
  2217. if (intf->curr_channel >= IPMI_MAX_CHANNELS)
  2218. wake_up(&intf->waitq);
  2219. else
  2220. rv = send_channel_info_cmd(intf, intf->curr_channel);
  2221. if (rv) {
  2222. /* Got an error somehow, just give up. */
  2223. intf->curr_channel = IPMI_MAX_CHANNELS;
  2224. wake_up(&intf->waitq);
  2225. printk(KERN_WARNING PFX
  2226. "Error sending channel information: %d\n",
  2227. rv);
  2228. }
  2229. }
  2230. out:
  2231. return;
  2232. }
  2233. void ipmi_poll_interface(ipmi_user_t user)
  2234. {
  2235. ipmi_smi_t intf = user->intf;
  2236. if (intf->handlers->poll)
  2237. intf->handlers->poll(intf->send_info);
  2238. }
  2239. int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
  2240. void *send_info,
  2241. struct ipmi_device_id *device_id,
  2242. struct device *si_dev,
  2243. const char *sysfs_name,
  2244. unsigned char slave_addr)
  2245. {
  2246. int i, j;
  2247. int rv;
  2248. ipmi_smi_t intf;
  2249. ipmi_smi_t tintf;
  2250. struct list_head *link;
  2251. /* Make sure the driver is actually initialized, this handles
  2252. problems with initialization order. */
  2253. if (!initialized) {
  2254. rv = ipmi_init_msghandler();
  2255. if (rv)
  2256. return rv;
  2257. /* The init code doesn't return an error if it was turned
  2258. off, but it won't initialize. Check that. */
  2259. if (!initialized)
  2260. return -ENODEV;
  2261. }
  2262. intf = kzalloc(sizeof(*intf), GFP_KERNEL);
  2263. if (!intf)
  2264. return -ENOMEM;
  2265. intf->ipmi_version_major = ipmi_version_major(device_id);
  2266. intf->ipmi_version_minor = ipmi_version_minor(device_id);
  2267. intf->bmc = kzalloc(sizeof(*intf->bmc), GFP_KERNEL);
  2268. if (!intf->bmc) {
  2269. kfree(intf);
  2270. return -ENOMEM;
  2271. }
  2272. intf->intf_num = -1; /* Mark it invalid for now. */
  2273. kref_init(&intf->refcount);
  2274. intf->bmc->id = *device_id;
  2275. intf->si_dev = si_dev;
  2276. for (j = 0; j < IPMI_MAX_CHANNELS; j++) {
  2277. intf->channels[j].address = IPMI_BMC_SLAVE_ADDR;
  2278. intf->channels[j].lun = 2;
  2279. }
  2280. if (slave_addr != 0)
  2281. intf->channels[0].address = slave_addr;
  2282. INIT_LIST_HEAD(&intf->users);
  2283. intf->handlers = handlers;
  2284. intf->send_info = send_info;
  2285. spin_lock_init(&intf->seq_lock);
  2286. for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) {
  2287. intf->seq_table[j].inuse = 0;
  2288. intf->seq_table[j].seqid = 0;
  2289. }
  2290. intf->curr_seq = 0;
  2291. #ifdef CONFIG_PROC_FS
  2292. mutex_init(&intf->proc_entry_lock);
  2293. #endif
  2294. spin_lock_init(&intf->waiting_msgs_lock);
  2295. INIT_LIST_HEAD(&intf->waiting_msgs);
  2296. spin_lock_init(&intf->events_lock);
  2297. INIT_LIST_HEAD(&intf->waiting_events);
  2298. intf->waiting_events_count = 0;
  2299. mutex_init(&intf->cmd_rcvrs_mutex);
  2300. spin_lock_init(&intf->maintenance_mode_lock);
  2301. INIT_LIST_HEAD(&intf->cmd_rcvrs);
  2302. init_waitqueue_head(&intf->waitq);
  2303. spin_lock_init(&intf->counter_lock);
  2304. intf->proc_dir = NULL;
  2305. mutex_lock(&smi_watchers_mutex);
  2306. mutex_lock(&ipmi_interfaces_mutex);
  2307. /* Look for a hole in the numbers. */
  2308. i = 0;
  2309. link = &ipmi_interfaces;
  2310. list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) {
  2311. if (tintf->intf_num != i) {
  2312. link = &tintf->link;
  2313. break;
  2314. }
  2315. i++;
  2316. }
  2317. /* Add the new interface in numeric order. */
  2318. if (i == 0)
  2319. list_add_rcu(&intf->link, &ipmi_interfaces);
  2320. else
  2321. list_add_tail_rcu(&intf->link, link);
  2322. rv = handlers->start_processing(send_info, intf);
  2323. if (rv)
  2324. goto out;
  2325. get_guid(intf);
  2326. if ((intf->ipmi_version_major > 1)
  2327. || ((intf->ipmi_version_major == 1)
  2328. && (intf->ipmi_version_minor >= 5)))
  2329. {
  2330. /* Start scanning the channels to see what is
  2331. available. */
  2332. intf->null_user_handler = channel_handler;
  2333. intf->curr_channel = 0;
  2334. rv = send_channel_info_cmd(intf, 0);
  2335. if (rv)
  2336. goto out;
  2337. /* Wait for the channel info to be read. */
  2338. wait_event(intf->waitq,
  2339. intf->curr_channel >= IPMI_MAX_CHANNELS);
  2340. intf->null_user_handler = NULL;
  2341. } else {
  2342. /* Assume a single IPMB channel at zero. */
  2343. intf->channels[0].medium = IPMI_CHANNEL_MEDIUM_IPMB;
  2344. intf->channels[0].protocol = IPMI_CHANNEL_PROTOCOL_IPMB;
  2345. }
  2346. if (rv == 0)
  2347. rv = add_proc_entries(intf, i);
  2348. rv = ipmi_bmc_register(intf, i, sysfs_name);
  2349. out:
  2350. if (rv) {
  2351. if (intf->proc_dir)
  2352. remove_proc_entries(intf);
  2353. intf->handlers = NULL;
  2354. list_del_rcu(&intf->link);
  2355. mutex_unlock(&ipmi_interfaces_mutex);
  2356. mutex_unlock(&smi_watchers_mutex);
  2357. synchronize_rcu();
  2358. kref_put(&intf->refcount, intf_free);
  2359. } else {
  2360. /*
  2361. * Keep memory order straight for RCU readers. Make
  2362. * sure everything else is committed to memory before
  2363. * setting intf_num to mark the interface valid.
  2364. */
  2365. smp_wmb();
  2366. intf->intf_num = i;
  2367. mutex_unlock(&ipmi_interfaces_mutex);
  2368. /* After this point the interface is legal to use. */
  2369. call_smi_watchers(i, intf->si_dev);
  2370. mutex_unlock(&smi_watchers_mutex);
  2371. }
  2372. return rv;
  2373. }
  2374. static void cleanup_smi_msgs(ipmi_smi_t intf)
  2375. {
  2376. int i;
  2377. struct seq_table *ent;
  2378. /* No need for locks, the interface is down. */
  2379. for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
  2380. ent = &(intf->seq_table[i]);
  2381. if (!ent->inuse)
  2382. continue;
  2383. deliver_err_response(ent->recv_msg, IPMI_ERR_UNSPECIFIED);
  2384. }
  2385. }
  2386. int ipmi_unregister_smi(ipmi_smi_t intf)
  2387. {
  2388. struct ipmi_smi_watcher *w;
  2389. int intf_num = intf->intf_num;
  2390. ipmi_bmc_unregister(intf);
  2391. mutex_lock(&smi_watchers_mutex);
  2392. mutex_lock(&ipmi_interfaces_mutex);
  2393. intf->intf_num = -1;
  2394. intf->handlers = NULL;
  2395. list_del_rcu(&intf->link);
  2396. mutex_unlock(&ipmi_interfaces_mutex);
  2397. synchronize_rcu();
  2398. cleanup_smi_msgs(intf);
  2399. remove_proc_entries(intf);
  2400. /* Call all the watcher interfaces to tell them that
  2401. an interface is gone. */
  2402. list_for_each_entry(w, &smi_watchers, link)
  2403. w->smi_gone(intf_num);
  2404. mutex_unlock(&smi_watchers_mutex);
  2405. kref_put(&intf->refcount, intf_free);
  2406. return 0;
  2407. }
  2408. static int handle_ipmb_get_msg_rsp(ipmi_smi_t intf,
  2409. struct ipmi_smi_msg *msg)
  2410. {
  2411. struct ipmi_ipmb_addr ipmb_addr;
  2412. struct ipmi_recv_msg *recv_msg;
  2413. unsigned long flags;
  2414. /* This is 11, not 10, because the response must contain a
  2415. * completion code. */
  2416. if (msg->rsp_size < 11) {
  2417. /* Message not big enough, just ignore it. */
  2418. spin_lock_irqsave(&intf->counter_lock, flags);
  2419. intf->invalid_ipmb_responses++;
  2420. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2421. return 0;
  2422. }
  2423. if (msg->rsp[2] != 0) {
  2424. /* An error getting the response, just ignore it. */
  2425. return 0;
  2426. }
  2427. ipmb_addr.addr_type = IPMI_IPMB_ADDR_TYPE;
  2428. ipmb_addr.slave_addr = msg->rsp[6];
  2429. ipmb_addr.channel = msg->rsp[3] & 0x0f;
  2430. ipmb_addr.lun = msg->rsp[7] & 3;
  2431. /* It's a response from a remote entity. Look up the sequence
  2432. number and handle the response. */
  2433. if (intf_find_seq(intf,
  2434. msg->rsp[7] >> 2,
  2435. msg->rsp[3] & 0x0f,
  2436. msg->rsp[8],
  2437. (msg->rsp[4] >> 2) & (~1),
  2438. (struct ipmi_addr *) &(ipmb_addr),
  2439. &recv_msg))
  2440. {
  2441. /* We were unable to find the sequence number,
  2442. so just nuke the message. */
  2443. spin_lock_irqsave(&intf->counter_lock, flags);
  2444. intf->unhandled_ipmb_responses++;
  2445. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2446. return 0;
  2447. }
  2448. memcpy(recv_msg->msg_data,
  2449. &(msg->rsp[9]),
  2450. msg->rsp_size - 9);
  2451. /* THe other fields matched, so no need to set them, except
  2452. for netfn, which needs to be the response that was
  2453. returned, not the request value. */
  2454. recv_msg->msg.netfn = msg->rsp[4] >> 2;
  2455. recv_msg->msg.data = recv_msg->msg_data;
  2456. recv_msg->msg.data_len = msg->rsp_size - 10;
  2457. recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
  2458. spin_lock_irqsave(&intf->counter_lock, flags);
  2459. intf->handled_ipmb_responses++;
  2460. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2461. deliver_response(recv_msg);
  2462. return 0;
  2463. }
  2464. static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
  2465. struct ipmi_smi_msg *msg)
  2466. {
  2467. struct cmd_rcvr *rcvr;
  2468. int rv = 0;
  2469. unsigned char netfn;
  2470. unsigned char cmd;
  2471. unsigned char chan;
  2472. ipmi_user_t user = NULL;
  2473. struct ipmi_ipmb_addr *ipmb_addr;
  2474. struct ipmi_recv_msg *recv_msg;
  2475. unsigned long flags;
  2476. struct ipmi_smi_handlers *handlers;
  2477. if (msg->rsp_size < 10) {
  2478. /* Message not big enough, just ignore it. */
  2479. spin_lock_irqsave(&intf->counter_lock, flags);
  2480. intf->invalid_commands++;
  2481. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2482. return 0;
  2483. }
  2484. if (msg->rsp[2] != 0) {
  2485. /* An error getting the response, just ignore it. */
  2486. return 0;
  2487. }
  2488. netfn = msg->rsp[4] >> 2;
  2489. cmd = msg->rsp[8];
  2490. chan = msg->rsp[3] & 0xf;
  2491. rcu_read_lock();
  2492. rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
  2493. if (rcvr) {
  2494. user = rcvr->user;
  2495. kref_get(&user->refcount);
  2496. } else
  2497. user = NULL;
  2498. rcu_read_unlock();
  2499. if (user == NULL) {
  2500. /* We didn't find a user, deliver an error response. */
  2501. spin_lock_irqsave(&intf->counter_lock, flags);
  2502. intf->unhandled_commands++;
  2503. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2504. msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
  2505. msg->data[1] = IPMI_SEND_MSG_CMD;
  2506. msg->data[2] = msg->rsp[3];
  2507. msg->data[3] = msg->rsp[6];
  2508. msg->data[4] = ((netfn + 1) << 2) | (msg->rsp[7] & 0x3);
  2509. msg->data[5] = ipmb_checksum(&(msg->data[3]), 2);
  2510. msg->data[6] = intf->channels[msg->rsp[3] & 0xf].address;
  2511. /* rqseq/lun */
  2512. msg->data[7] = (msg->rsp[7] & 0xfc) | (msg->rsp[4] & 0x3);
  2513. msg->data[8] = msg->rsp[8]; /* cmd */
  2514. msg->data[9] = IPMI_INVALID_CMD_COMPLETION_CODE;
  2515. msg->data[10] = ipmb_checksum(&(msg->data[6]), 4);
  2516. msg->data_size = 11;
  2517. #ifdef DEBUG_MSGING
  2518. {
  2519. int m;
  2520. printk("Invalid command:");
  2521. for (m = 0; m < msg->data_size; m++)
  2522. printk(" %2.2x", msg->data[m]);
  2523. printk("\n");
  2524. }
  2525. #endif
  2526. rcu_read_lock();
  2527. handlers = intf->handlers;
  2528. if (handlers) {
  2529. handlers->sender(intf->send_info, msg, 0);
  2530. /* We used the message, so return the value
  2531. that causes it to not be freed or
  2532. queued. */
  2533. rv = -1;
  2534. }
  2535. rcu_read_unlock();
  2536. } else {
  2537. /* Deliver the message to the user. */
  2538. spin_lock_irqsave(&intf->counter_lock, flags);
  2539. intf->handled_commands++;
  2540. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2541. recv_msg = ipmi_alloc_recv_msg();
  2542. if (!recv_msg) {
  2543. /* We couldn't allocate memory for the
  2544. message, so requeue it for handling
  2545. later. */
  2546. rv = 1;
  2547. kref_put(&user->refcount, free_user);
  2548. } else {
  2549. /* Extract the source address from the data. */
  2550. ipmb_addr = (struct ipmi_ipmb_addr *) &recv_msg->addr;
  2551. ipmb_addr->addr_type = IPMI_IPMB_ADDR_TYPE;
  2552. ipmb_addr->slave_addr = msg->rsp[6];
  2553. ipmb_addr->lun = msg->rsp[7] & 3;
  2554. ipmb_addr->channel = msg->rsp[3] & 0xf;
  2555. /* Extract the rest of the message information
  2556. from the IPMB header.*/
  2557. recv_msg->user = user;
  2558. recv_msg->recv_type = IPMI_CMD_RECV_TYPE;
  2559. recv_msg->msgid = msg->rsp[7] >> 2;
  2560. recv_msg->msg.netfn = msg->rsp[4] >> 2;
  2561. recv_msg->msg.cmd = msg->rsp[8];
  2562. recv_msg->msg.data = recv_msg->msg_data;
  2563. /* We chop off 10, not 9 bytes because the checksum
  2564. at the end also needs to be removed. */
  2565. recv_msg->msg.data_len = msg->rsp_size - 10;
  2566. memcpy(recv_msg->msg_data,
  2567. &(msg->rsp[9]),
  2568. msg->rsp_size - 10);
  2569. deliver_response(recv_msg);
  2570. }
  2571. }
  2572. return rv;
  2573. }
  2574. static int handle_lan_get_msg_rsp(ipmi_smi_t intf,
  2575. struct ipmi_smi_msg *msg)
  2576. {
  2577. struct ipmi_lan_addr lan_addr;
  2578. struct ipmi_recv_msg *recv_msg;
  2579. unsigned long flags;
  2580. /* This is 13, not 12, because the response must contain a
  2581. * completion code. */
  2582. if (msg->rsp_size < 13) {
  2583. /* Message not big enough, just ignore it. */
  2584. spin_lock_irqsave(&intf->counter_lock, flags);
  2585. intf->invalid_lan_responses++;
  2586. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2587. return 0;
  2588. }
  2589. if (msg->rsp[2] != 0) {
  2590. /* An error getting the response, just ignore it. */
  2591. return 0;
  2592. }
  2593. lan_addr.addr_type = IPMI_LAN_ADDR_TYPE;
  2594. lan_addr.session_handle = msg->rsp[4];
  2595. lan_addr.remote_SWID = msg->rsp[8];
  2596. lan_addr.local_SWID = msg->rsp[5];
  2597. lan_addr.channel = msg->rsp[3] & 0x0f;
  2598. lan_addr.privilege = msg->rsp[3] >> 4;
  2599. lan_addr.lun = msg->rsp[9] & 3;
  2600. /* It's a response from a remote entity. Look up the sequence
  2601. number and handle the response. */
  2602. if (intf_find_seq(intf,
  2603. msg->rsp[9] >> 2,
  2604. msg->rsp[3] & 0x0f,
  2605. msg->rsp[10],
  2606. (msg->rsp[6] >> 2) & (~1),
  2607. (struct ipmi_addr *) &(lan_addr),
  2608. &recv_msg))
  2609. {
  2610. /* We were unable to find the sequence number,
  2611. so just nuke the message. */
  2612. spin_lock_irqsave(&intf->counter_lock, flags);
  2613. intf->unhandled_lan_responses++;
  2614. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2615. return 0;
  2616. }
  2617. memcpy(recv_msg->msg_data,
  2618. &(msg->rsp[11]),
  2619. msg->rsp_size - 11);
  2620. /* The other fields matched, so no need to set them, except
  2621. for netfn, which needs to be the response that was
  2622. returned, not the request value. */
  2623. recv_msg->msg.netfn = msg->rsp[6] >> 2;
  2624. recv_msg->msg.data = recv_msg->msg_data;
  2625. recv_msg->msg.data_len = msg->rsp_size - 12;
  2626. recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
  2627. spin_lock_irqsave(&intf->counter_lock, flags);
  2628. intf->handled_lan_responses++;
  2629. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2630. deliver_response(recv_msg);
  2631. return 0;
  2632. }
  2633. static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
  2634. struct ipmi_smi_msg *msg)
  2635. {
  2636. struct cmd_rcvr *rcvr;
  2637. int rv = 0;
  2638. unsigned char netfn;
  2639. unsigned char cmd;
  2640. unsigned char chan;
  2641. ipmi_user_t user = NULL;
  2642. struct ipmi_lan_addr *lan_addr;
  2643. struct ipmi_recv_msg *recv_msg;
  2644. unsigned long flags;
  2645. if (msg->rsp_size < 12) {
  2646. /* Message not big enough, just ignore it. */
  2647. spin_lock_irqsave(&intf->counter_lock, flags);
  2648. intf->invalid_commands++;
  2649. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2650. return 0;
  2651. }
  2652. if (msg->rsp[2] != 0) {
  2653. /* An error getting the response, just ignore it. */
  2654. return 0;
  2655. }
  2656. netfn = msg->rsp[6] >> 2;
  2657. cmd = msg->rsp[10];
  2658. chan = msg->rsp[3] & 0xf;
  2659. rcu_read_lock();
  2660. rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
  2661. if (rcvr) {
  2662. user = rcvr->user;
  2663. kref_get(&user->refcount);
  2664. } else
  2665. user = NULL;
  2666. rcu_read_unlock();
  2667. if (user == NULL) {
  2668. /* We didn't find a user, just give up. */
  2669. spin_lock_irqsave(&intf->counter_lock, flags);
  2670. intf->unhandled_commands++;
  2671. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2672. rv = 0; /* Don't do anything with these messages, just
  2673. allow them to be freed. */
  2674. } else {
  2675. /* Deliver the message to the user. */
  2676. spin_lock_irqsave(&intf->counter_lock, flags);
  2677. intf->handled_commands++;
  2678. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2679. recv_msg = ipmi_alloc_recv_msg();
  2680. if (!recv_msg) {
  2681. /* We couldn't allocate memory for the
  2682. message, so requeue it for handling
  2683. later. */
  2684. rv = 1;
  2685. kref_put(&user->refcount, free_user);
  2686. } else {
  2687. /* Extract the source address from the data. */
  2688. lan_addr = (struct ipmi_lan_addr *) &recv_msg->addr;
  2689. lan_addr->addr_type = IPMI_LAN_ADDR_TYPE;
  2690. lan_addr->session_handle = msg->rsp[4];
  2691. lan_addr->remote_SWID = msg->rsp[8];
  2692. lan_addr->local_SWID = msg->rsp[5];
  2693. lan_addr->lun = msg->rsp[9] & 3;
  2694. lan_addr->channel = msg->rsp[3] & 0xf;
  2695. lan_addr->privilege = msg->rsp[3] >> 4;
  2696. /* Extract the rest of the message information
  2697. from the IPMB header.*/
  2698. recv_msg->user = user;
  2699. recv_msg->recv_type = IPMI_CMD_RECV_TYPE;
  2700. recv_msg->msgid = msg->rsp[9] >> 2;
  2701. recv_msg->msg.netfn = msg->rsp[6] >> 2;
  2702. recv_msg->msg.cmd = msg->rsp[10];
  2703. recv_msg->msg.data = recv_msg->msg_data;
  2704. /* We chop off 12, not 11 bytes because the checksum
  2705. at the end also needs to be removed. */
  2706. recv_msg->msg.data_len = msg->rsp_size - 12;
  2707. memcpy(recv_msg->msg_data,
  2708. &(msg->rsp[11]),
  2709. msg->rsp_size - 12);
  2710. deliver_response(recv_msg);
  2711. }
  2712. }
  2713. return rv;
  2714. }
  2715. static void copy_event_into_recv_msg(struct ipmi_recv_msg *recv_msg,
  2716. struct ipmi_smi_msg *msg)
  2717. {
  2718. struct ipmi_system_interface_addr *smi_addr;
  2719. recv_msg->msgid = 0;
  2720. smi_addr = (struct ipmi_system_interface_addr *) &(recv_msg->addr);
  2721. smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  2722. smi_addr->channel = IPMI_BMC_CHANNEL;
  2723. smi_addr->lun = msg->rsp[0] & 3;
  2724. recv_msg->recv_type = IPMI_ASYNC_EVENT_RECV_TYPE;
  2725. recv_msg->msg.netfn = msg->rsp[0] >> 2;
  2726. recv_msg->msg.cmd = msg->rsp[1];
  2727. memcpy(recv_msg->msg_data, &(msg->rsp[3]), msg->rsp_size - 3);
  2728. recv_msg->msg.data = recv_msg->msg_data;
  2729. recv_msg->msg.data_len = msg->rsp_size - 3;
  2730. }
  2731. static int handle_read_event_rsp(ipmi_smi_t intf,
  2732. struct ipmi_smi_msg *msg)
  2733. {
  2734. struct ipmi_recv_msg *recv_msg, *recv_msg2;
  2735. struct list_head msgs;
  2736. ipmi_user_t user;
  2737. int rv = 0;
  2738. int deliver_count = 0;
  2739. unsigned long flags;
  2740. if (msg->rsp_size < 19) {
  2741. /* Message is too small to be an IPMB event. */
  2742. spin_lock_irqsave(&intf->counter_lock, flags);
  2743. intf->invalid_events++;
  2744. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2745. return 0;
  2746. }
  2747. if (msg->rsp[2] != 0) {
  2748. /* An error getting the event, just ignore it. */
  2749. return 0;
  2750. }
  2751. INIT_LIST_HEAD(&msgs);
  2752. spin_lock_irqsave(&intf->events_lock, flags);
  2753. spin_lock(&intf->counter_lock);
  2754. intf->events++;
  2755. spin_unlock(&intf->counter_lock);
  2756. /* Allocate and fill in one message for every user that is getting
  2757. events. */
  2758. rcu_read_lock();
  2759. list_for_each_entry_rcu(user, &intf->users, link) {
  2760. if (!user->gets_events)
  2761. continue;
  2762. recv_msg = ipmi_alloc_recv_msg();
  2763. if (!recv_msg) {
  2764. rcu_read_unlock();
  2765. list_for_each_entry_safe(recv_msg, recv_msg2, &msgs,
  2766. link) {
  2767. list_del(&recv_msg->link);
  2768. ipmi_free_recv_msg(recv_msg);
  2769. }
  2770. /* We couldn't allocate memory for the
  2771. message, so requeue it for handling
  2772. later. */
  2773. rv = 1;
  2774. goto out;
  2775. }
  2776. deliver_count++;
  2777. copy_event_into_recv_msg(recv_msg, msg);
  2778. recv_msg->user = user;
  2779. kref_get(&user->refcount);
  2780. list_add_tail(&(recv_msg->link), &msgs);
  2781. }
  2782. rcu_read_unlock();
  2783. if (deliver_count) {
  2784. /* Now deliver all the messages. */
  2785. list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, link) {
  2786. list_del(&recv_msg->link);
  2787. deliver_response(recv_msg);
  2788. }
  2789. } else if (intf->waiting_events_count < MAX_EVENTS_IN_QUEUE) {
  2790. /* No one to receive the message, put it in queue if there's
  2791. not already too many things in the queue. */
  2792. recv_msg = ipmi_alloc_recv_msg();
  2793. if (!recv_msg) {
  2794. /* We couldn't allocate memory for the
  2795. message, so requeue it for handling
  2796. later. */
  2797. rv = 1;
  2798. goto out;
  2799. }
  2800. copy_event_into_recv_msg(recv_msg, msg);
  2801. list_add_tail(&(recv_msg->link), &(intf->waiting_events));
  2802. intf->waiting_events_count++;
  2803. } else {
  2804. /* There's too many things in the queue, discard this
  2805. message. */
  2806. printk(KERN_WARNING PFX "Event queue full, discarding an"
  2807. " incoming event\n");
  2808. }
  2809. out:
  2810. spin_unlock_irqrestore(&(intf->events_lock), flags);
  2811. return rv;
  2812. }
  2813. static int handle_bmc_rsp(ipmi_smi_t intf,
  2814. struct ipmi_smi_msg *msg)
  2815. {
  2816. struct ipmi_recv_msg *recv_msg;
  2817. unsigned long flags;
  2818. struct ipmi_user *user;
  2819. recv_msg = (struct ipmi_recv_msg *) msg->user_data;
  2820. if (recv_msg == NULL)
  2821. {
  2822. printk(KERN_WARNING"IPMI message received with no owner. This\n"
  2823. "could be because of a malformed message, or\n"
  2824. "because of a hardware error. Contact your\n"
  2825. "hardware vender for assistance\n");
  2826. return 0;
  2827. }
  2828. user = recv_msg->user;
  2829. /* Make sure the user still exists. */
  2830. if (user && !user->valid) {
  2831. /* The user for the message went away, so give up. */
  2832. spin_lock_irqsave(&intf->counter_lock, flags);
  2833. intf->unhandled_local_responses++;
  2834. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2835. ipmi_free_recv_msg(recv_msg);
  2836. } else {
  2837. struct ipmi_system_interface_addr *smi_addr;
  2838. spin_lock_irqsave(&intf->counter_lock, flags);
  2839. intf->handled_local_responses++;
  2840. spin_unlock_irqrestore(&intf->counter_lock, flags);
  2841. recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
  2842. recv_msg->msgid = msg->msgid;
  2843. smi_addr = ((struct ipmi_system_interface_addr *)
  2844. &(recv_msg->addr));
  2845. smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  2846. smi_addr->channel = IPMI_BMC_CHANNEL;
  2847. smi_addr->lun = msg->rsp[0] & 3;
  2848. recv_msg->msg.netfn = msg->rsp[0] >> 2;
  2849. recv_msg->msg.cmd = msg->rsp[1];
  2850. memcpy(recv_msg->msg_data,
  2851. &(msg->rsp[2]),
  2852. msg->rsp_size - 2);
  2853. recv_msg->msg.data = recv_msg->msg_data;
  2854. recv_msg->msg.data_len = msg->rsp_size - 2;
  2855. deliver_response(recv_msg);
  2856. }
  2857. return 0;
  2858. }
  2859. /* Handle a new message. Return 1 if the message should be requeued,
  2860. 0 if the message should be freed, or -1 if the message should not
  2861. be freed or requeued. */
  2862. static int handle_new_recv_msg(ipmi_smi_t intf,
  2863. struct ipmi_smi_msg *msg)
  2864. {
  2865. int requeue;
  2866. int chan;
  2867. #ifdef DEBUG_MSGING
  2868. int m;
  2869. printk("Recv:");
  2870. for (m = 0; m < msg->rsp_size; m++)
  2871. printk(" %2.2x", msg->rsp[m]);
  2872. printk("\n");
  2873. #endif
  2874. if (msg->rsp_size < 2) {
  2875. /* Message is too small to be correct. */
  2876. printk(KERN_WARNING PFX "BMC returned to small a message"
  2877. " for netfn %x cmd %x, got %d bytes\n",
  2878. (msg->data[0] >> 2) | 1, msg->data[1], msg->rsp_size);
  2879. /* Generate an error response for the message. */
  2880. msg->rsp[0] = msg->data[0] | (1 << 2);
  2881. msg->rsp[1] = msg->data[1];
  2882. msg->rsp[2] = IPMI_ERR_UNSPECIFIED;
  2883. msg->rsp_size = 3;
  2884. } else if (((msg->rsp[0] >> 2) != ((msg->data[0] >> 2) | 1))/* Netfn */
  2885. || (msg->rsp[1] != msg->data[1])) /* Command */
  2886. {
  2887. /* The response is not even marginally correct. */
  2888. printk(KERN_WARNING PFX "BMC returned incorrect response,"
  2889. " expected netfn %x cmd %x, got netfn %x cmd %x\n",
  2890. (msg->data[0] >> 2) | 1, msg->data[1],
  2891. msg->rsp[0] >> 2, msg->rsp[1]);
  2892. /* Generate an error response for the message. */
  2893. msg->rsp[0] = msg->data[0] | (1 << 2);
  2894. msg->rsp[1] = msg->data[1];
  2895. msg->rsp[2] = IPMI_ERR_UNSPECIFIED;
  2896. msg->rsp_size = 3;
  2897. }
  2898. if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2))
  2899. && (msg->rsp[1] == IPMI_SEND_MSG_CMD)
  2900. && (msg->user_data != NULL))
  2901. {
  2902. /* It's a response to a response we sent. For this we
  2903. deliver a send message response to the user. */
  2904. struct ipmi_recv_msg *recv_msg = msg->user_data;
  2905. requeue = 0;
  2906. if (msg->rsp_size < 2)
  2907. /* Message is too small to be correct. */
  2908. goto out;
  2909. chan = msg->data[2] & 0x0f;
  2910. if (chan >= IPMI_MAX_CHANNELS)
  2911. /* Invalid channel number */
  2912. goto out;
  2913. if (!recv_msg)
  2914. goto out;
  2915. /* Make sure the user still exists. */
  2916. if (!recv_msg->user || !recv_msg->user->valid)
  2917. goto out;
  2918. recv_msg->recv_type = IPMI_RESPONSE_RESPONSE_TYPE;
  2919. recv_msg->msg.data = recv_msg->msg_data;
  2920. recv_msg->msg.data_len = 1;
  2921. recv_msg->msg_data[0] = msg->rsp[2];
  2922. deliver_response(recv_msg);
  2923. } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2))
  2924. && (msg->rsp[1] == IPMI_GET_MSG_CMD))
  2925. {
  2926. /* It's from the receive queue. */
  2927. chan = msg->rsp[3] & 0xf;
  2928. if (chan >= IPMI_MAX_CHANNELS) {
  2929. /* Invalid channel number */
  2930. requeue = 0;
  2931. goto out;
  2932. }
  2933. switch (intf->channels[chan].medium) {
  2934. case IPMI_CHANNEL_MEDIUM_IPMB:
  2935. if (msg->rsp[4] & 0x04) {
  2936. /* It's a response, so find the
  2937. requesting message and send it up. */
  2938. requeue = handle_ipmb_get_msg_rsp(intf, msg);
  2939. } else {
  2940. /* It's a command to the SMS from some other
  2941. entity. Handle that. */
  2942. requeue = handle_ipmb_get_msg_cmd(intf, msg);
  2943. }
  2944. break;
  2945. case IPMI_CHANNEL_MEDIUM_8023LAN:
  2946. case IPMI_CHANNEL_MEDIUM_ASYNC:
  2947. if (msg->rsp[6] & 0x04) {
  2948. /* It's a response, so find the
  2949. requesting message and send it up. */
  2950. requeue = handle_lan_get_msg_rsp(intf, msg);
  2951. } else {
  2952. /* It's a command to the SMS from some other
  2953. entity. Handle that. */
  2954. requeue = handle_lan_get_msg_cmd(intf, msg);
  2955. }
  2956. break;
  2957. default:
  2958. /* We don't handle the channel type, so just
  2959. * free the message. */
  2960. requeue = 0;
  2961. }
  2962. } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2))
  2963. && (msg->rsp[1] == IPMI_READ_EVENT_MSG_BUFFER_CMD))
  2964. {
  2965. /* It's an asyncronous event. */
  2966. requeue = handle_read_event_rsp(intf, msg);
  2967. } else {
  2968. /* It's a response from the local BMC. */
  2969. requeue = handle_bmc_rsp(intf, msg);
  2970. }
  2971. out:
  2972. return requeue;
  2973. }
  2974. /* Handle a new message from the lower layer. */
  2975. void ipmi_smi_msg_received(ipmi_smi_t intf,
  2976. struct ipmi_smi_msg *msg)
  2977. {
  2978. unsigned long flags;
  2979. int rv;
  2980. if ((msg->data_size >= 2)
  2981. && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2))
  2982. && (msg->data[1] == IPMI_SEND_MSG_CMD)
  2983. && (msg->user_data == NULL))
  2984. {
  2985. /* This is the local response to a command send, start
  2986. the timer for these. The user_data will not be
  2987. NULL if this is a response send, and we will let
  2988. response sends just go through. */
  2989. /* Check for errors, if we get certain errors (ones
  2990. that mean basically we can try again later), we
  2991. ignore them and start the timer. Otherwise we
  2992. report the error immediately. */
  2993. if ((msg->rsp_size >= 3) && (msg->rsp[2] != 0)
  2994. && (msg->rsp[2] != IPMI_NODE_BUSY_ERR)
  2995. && (msg->rsp[2] != IPMI_LOST_ARBITRATION_ERR)
  2996. && (msg->rsp[2] != IPMI_BUS_ERR)
  2997. && (msg->rsp[2] != IPMI_NAK_ON_WRITE_ERR))
  2998. {
  2999. int chan = msg->rsp[3] & 0xf;
  3000. /* Got an error sending the message, handle it. */
  3001. spin_lock_irqsave(&intf->counter_lock, flags);
  3002. if (chan >= IPMI_MAX_CHANNELS)
  3003. ; /* This shouldn't happen */
  3004. else if ((intf->channels[chan].medium
  3005. == IPMI_CHANNEL_MEDIUM_8023LAN)
  3006. || (intf->channels[chan].medium
  3007. == IPMI_CHANNEL_MEDIUM_ASYNC))
  3008. intf->sent_lan_command_errs++;
  3009. else
  3010. intf->sent_ipmb_command_errs++;
  3011. spin_unlock_irqrestore(&intf->counter_lock, flags);
  3012. intf_err_seq(intf, msg->msgid, msg->rsp[2]);
  3013. } else {
  3014. /* The message was sent, start the timer. */
  3015. intf_start_seq_timer(intf, msg->msgid);
  3016. }
  3017. ipmi_free_smi_msg(msg);
  3018. goto out;
  3019. }
  3020. /* To preserve message order, if the list is not empty, we
  3021. tack this message onto the end of the list. */
  3022. spin_lock_irqsave(&intf->waiting_msgs_lock, flags);
  3023. if (!list_empty(&intf->waiting_msgs)) {
  3024. list_add_tail(&msg->link, &intf->waiting_msgs);
  3025. spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags);
  3026. goto out;
  3027. }
  3028. spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags);
  3029. rv = handle_new_recv_msg(intf, msg);
  3030. if (rv > 0) {
  3031. /* Could not handle the message now, just add it to a
  3032. list to handle later. */
  3033. spin_lock_irqsave(&intf->waiting_msgs_lock, flags);
  3034. list_add_tail(&msg->link, &intf->waiting_msgs);
  3035. spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags);
  3036. } else if (rv == 0) {
  3037. ipmi_free_smi_msg(msg);
  3038. }
  3039. out:
  3040. return;
  3041. }
  3042. void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf)
  3043. {
  3044. ipmi_user_t user;
  3045. rcu_read_lock();
  3046. list_for_each_entry_rcu(user, &intf->users, link) {
  3047. if (!user->handler->ipmi_watchdog_pretimeout)
  3048. continue;
  3049. user->handler->ipmi_watchdog_pretimeout(user->handler_data);
  3050. }
  3051. rcu_read_unlock();
  3052. }
  3053. static struct ipmi_smi_msg *
  3054. smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg,
  3055. unsigned char seq, long seqid)
  3056. {
  3057. struct ipmi_smi_msg *smi_msg = ipmi_alloc_smi_msg();
  3058. if (!smi_msg)
  3059. /* If we can't allocate the message, then just return, we
  3060. get 4 retries, so this should be ok. */
  3061. return NULL;
  3062. memcpy(smi_msg->data, recv_msg->msg.data, recv_msg->msg.data_len);
  3063. smi_msg->data_size = recv_msg->msg.data_len;
  3064. smi_msg->msgid = STORE_SEQ_IN_MSGID(seq, seqid);
  3065. #ifdef DEBUG_MSGING
  3066. {
  3067. int m;
  3068. printk("Resend: ");
  3069. for (m = 0; m < smi_msg->data_size; m++)
  3070. printk(" %2.2x", smi_msg->data[m]);
  3071. printk("\n");
  3072. }
  3073. #endif
  3074. return smi_msg;
  3075. }
  3076. static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent,
  3077. struct list_head *timeouts, long timeout_period,
  3078. int slot, unsigned long *flags)
  3079. {
  3080. struct ipmi_recv_msg *msg;
  3081. struct ipmi_smi_handlers *handlers;
  3082. if (intf->intf_num == -1)
  3083. return;
  3084. if (!ent->inuse)
  3085. return;
  3086. ent->timeout -= timeout_period;
  3087. if (ent->timeout > 0)
  3088. return;
  3089. if (ent->retries_left == 0) {
  3090. /* The message has used all its retries. */
  3091. ent->inuse = 0;
  3092. msg = ent->recv_msg;
  3093. list_add_tail(&msg->link, timeouts);
  3094. spin_lock(&intf->counter_lock);
  3095. if (ent->broadcast)
  3096. intf->timed_out_ipmb_broadcasts++;
  3097. else if (ent->recv_msg->addr.addr_type == IPMI_LAN_ADDR_TYPE)
  3098. intf->timed_out_lan_commands++;
  3099. else
  3100. intf->timed_out_ipmb_commands++;
  3101. spin_unlock(&intf->counter_lock);
  3102. } else {
  3103. struct ipmi_smi_msg *smi_msg;
  3104. /* More retries, send again. */
  3105. /* Start with the max timer, set to normal
  3106. timer after the message is sent. */
  3107. ent->timeout = MAX_MSG_TIMEOUT;
  3108. ent->retries_left--;
  3109. spin_lock(&intf->counter_lock);
  3110. if (ent->recv_msg->addr.addr_type == IPMI_LAN_ADDR_TYPE)
  3111. intf->retransmitted_lan_commands++;
  3112. else
  3113. intf->retransmitted_ipmb_commands++;
  3114. spin_unlock(&intf->counter_lock);
  3115. smi_msg = smi_from_recv_msg(intf, ent->recv_msg, slot,
  3116. ent->seqid);
  3117. if (!smi_msg)
  3118. return;
  3119. spin_unlock_irqrestore(&intf->seq_lock, *flags);
  3120. /* Send the new message. We send with a zero
  3121. * priority. It timed out, I doubt time is
  3122. * that critical now, and high priority
  3123. * messages are really only for messages to the
  3124. * local MC, which don't get resent. */
  3125. handlers = intf->handlers;
  3126. if (handlers)
  3127. intf->handlers->sender(intf->send_info,
  3128. smi_msg, 0);
  3129. else
  3130. ipmi_free_smi_msg(smi_msg);
  3131. spin_lock_irqsave(&intf->seq_lock, *flags);
  3132. }
  3133. }
  3134. static void ipmi_timeout_handler(long timeout_period)
  3135. {
  3136. ipmi_smi_t intf;
  3137. struct list_head timeouts;
  3138. struct ipmi_recv_msg *msg, *msg2;
  3139. struct ipmi_smi_msg *smi_msg, *smi_msg2;
  3140. unsigned long flags;
  3141. int i;
  3142. rcu_read_lock();
  3143. list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
  3144. /* See if any waiting messages need to be processed. */
  3145. spin_lock_irqsave(&intf->waiting_msgs_lock, flags);
  3146. list_for_each_entry_safe(smi_msg, smi_msg2,
  3147. &intf->waiting_msgs, link) {
  3148. if (!handle_new_recv_msg(intf, smi_msg)) {
  3149. list_del(&smi_msg->link);
  3150. ipmi_free_smi_msg(smi_msg);
  3151. } else {
  3152. /* To preserve message order, quit if we
  3153. can't handle a message. */
  3154. break;
  3155. }
  3156. }
  3157. spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags);
  3158. /* Go through the seq table and find any messages that
  3159. have timed out, putting them in the timeouts
  3160. list. */
  3161. INIT_LIST_HEAD(&timeouts);
  3162. spin_lock_irqsave(&intf->seq_lock, flags);
  3163. for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++)
  3164. check_msg_timeout(intf, &(intf->seq_table[i]),
  3165. &timeouts, timeout_period, i,
  3166. &flags);
  3167. spin_unlock_irqrestore(&intf->seq_lock, flags);
  3168. list_for_each_entry_safe(msg, msg2, &timeouts, link)
  3169. deliver_err_response(msg, IPMI_TIMEOUT_COMPLETION_CODE);
  3170. /*
  3171. * Maintenance mode handling. Check the timeout
  3172. * optimistically before we claim the lock. It may
  3173. * mean a timeout gets missed occasionally, but that
  3174. * only means the timeout gets extended by one period
  3175. * in that case. No big deal, and it avoids the lock
  3176. * most of the time.
  3177. */
  3178. if (intf->auto_maintenance_timeout > 0) {
  3179. spin_lock_irqsave(&intf->maintenance_mode_lock, flags);
  3180. if (intf->auto_maintenance_timeout > 0) {
  3181. intf->auto_maintenance_timeout
  3182. -= timeout_period;
  3183. if (!intf->maintenance_mode
  3184. && (intf->auto_maintenance_timeout <= 0))
  3185. {
  3186. intf->maintenance_mode_enable = 0;
  3187. maintenance_mode_update(intf);
  3188. }
  3189. }
  3190. spin_unlock_irqrestore(&intf->maintenance_mode_lock,
  3191. flags);
  3192. }
  3193. }
  3194. rcu_read_unlock();
  3195. }
  3196. static void ipmi_request_event(void)
  3197. {
  3198. ipmi_smi_t intf;
  3199. struct ipmi_smi_handlers *handlers;
  3200. rcu_read_lock();
  3201. /* Called from the timer, no need to check if handlers is
  3202. * valid. */
  3203. list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
  3204. /* No event requests when in maintenance mode. */
  3205. if (intf->maintenance_mode_enable)
  3206. continue;
  3207. handlers = intf->handlers;
  3208. if (handlers)
  3209. handlers->request_events(intf->send_info);
  3210. }
  3211. rcu_read_unlock();
  3212. }
  3213. static struct timer_list ipmi_timer;
  3214. /* Call every ~100 ms. */
  3215. #define IPMI_TIMEOUT_TIME 100
  3216. /* How many jiffies does it take to get to the timeout time. */
  3217. #define IPMI_TIMEOUT_JIFFIES ((IPMI_TIMEOUT_TIME * HZ) / 1000)
  3218. /* Request events from the queue every second (this is the number of
  3219. IPMI_TIMEOUT_TIMES between event requests). Hopefully, in the
  3220. future, IPMI will add a way to know immediately if an event is in
  3221. the queue and this silliness can go away. */
  3222. #define IPMI_REQUEST_EV_TIME (1000 / (IPMI_TIMEOUT_TIME))
  3223. static atomic_t stop_operation;
  3224. static unsigned int ticks_to_req_ev = IPMI_REQUEST_EV_TIME;
  3225. static void ipmi_timeout(unsigned long data)
  3226. {
  3227. if (atomic_read(&stop_operation))
  3228. return;
  3229. ticks_to_req_ev--;
  3230. if (ticks_to_req_ev == 0) {
  3231. ipmi_request_event();
  3232. ticks_to_req_ev = IPMI_REQUEST_EV_TIME;
  3233. }
  3234. ipmi_timeout_handler(IPMI_TIMEOUT_TIME);
  3235. mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES);
  3236. }
  3237. static atomic_t smi_msg_inuse_count = ATOMIC_INIT(0);
  3238. static atomic_t recv_msg_inuse_count = ATOMIC_INIT(0);
  3239. /* FIXME - convert these to slabs. */
  3240. static void free_smi_msg(struct ipmi_smi_msg *msg)
  3241. {
  3242. atomic_dec(&smi_msg_inuse_count);
  3243. kfree(msg);
  3244. }
  3245. struct ipmi_smi_msg *ipmi_alloc_smi_msg(void)
  3246. {
  3247. struct ipmi_smi_msg *rv;
  3248. rv = kmalloc(sizeof(struct ipmi_smi_msg), GFP_ATOMIC);
  3249. if (rv) {
  3250. rv->done = free_smi_msg;
  3251. rv->user_data = NULL;
  3252. atomic_inc(&smi_msg_inuse_count);
  3253. }
  3254. return rv;
  3255. }
  3256. static void free_recv_msg(struct ipmi_recv_msg *msg)
  3257. {
  3258. atomic_dec(&recv_msg_inuse_count);
  3259. kfree(msg);
  3260. }
  3261. struct ipmi_recv_msg *ipmi_alloc_recv_msg(void)
  3262. {
  3263. struct ipmi_recv_msg *rv;
  3264. rv = kmalloc(sizeof(struct ipmi_recv_msg), GFP_ATOMIC);
  3265. if (rv) {
  3266. rv->user = NULL;
  3267. rv->done = free_recv_msg;
  3268. atomic_inc(&recv_msg_inuse_count);
  3269. }
  3270. return rv;
  3271. }
  3272. void ipmi_free_recv_msg(struct ipmi_recv_msg *msg)
  3273. {
  3274. if (msg->user)
  3275. kref_put(&msg->user->refcount, free_user);
  3276. msg->done(msg);
  3277. }
  3278. #ifdef CONFIG_IPMI_PANIC_EVENT
  3279. static void dummy_smi_done_handler(struct ipmi_smi_msg *msg)
  3280. {
  3281. }
  3282. static void dummy_recv_done_handler(struct ipmi_recv_msg *msg)
  3283. {
  3284. }
  3285. #ifdef CONFIG_IPMI_PANIC_STRING
  3286. static void event_receiver_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
  3287. {
  3288. if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
  3289. && (msg->msg.netfn == IPMI_NETFN_SENSOR_EVENT_RESPONSE)
  3290. && (msg->msg.cmd == IPMI_GET_EVENT_RECEIVER_CMD)
  3291. && (msg->msg.data[0] == IPMI_CC_NO_ERROR))
  3292. {
  3293. /* A get event receiver command, save it. */
  3294. intf->event_receiver = msg->msg.data[1];
  3295. intf->event_receiver_lun = msg->msg.data[2] & 0x3;
  3296. }
  3297. }
  3298. static void device_id_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
  3299. {
  3300. if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
  3301. && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE)
  3302. && (msg->msg.cmd == IPMI_GET_DEVICE_ID_CMD)
  3303. && (msg->msg.data[0] == IPMI_CC_NO_ERROR))
  3304. {
  3305. /* A get device id command, save if we are an event
  3306. receiver or generator. */
  3307. intf->local_sel_device = (msg->msg.data[6] >> 2) & 1;
  3308. intf->local_event_generator = (msg->msg.data[6] >> 5) & 1;
  3309. }
  3310. }
  3311. #endif
  3312. static void send_panic_events(char *str)
  3313. {
  3314. struct kernel_ipmi_msg msg;
  3315. ipmi_smi_t intf;
  3316. unsigned char data[16];
  3317. struct ipmi_system_interface_addr *si;
  3318. struct ipmi_addr addr;
  3319. struct ipmi_smi_msg smi_msg;
  3320. struct ipmi_recv_msg recv_msg;
  3321. si = (struct ipmi_system_interface_addr *) &addr;
  3322. si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  3323. si->channel = IPMI_BMC_CHANNEL;
  3324. si->lun = 0;
  3325. /* Fill in an event telling that we have failed. */
  3326. msg.netfn = 0x04; /* Sensor or Event. */
  3327. msg.cmd = 2; /* Platform event command. */
  3328. msg.data = data;
  3329. msg.data_len = 8;
  3330. data[0] = 0x41; /* Kernel generator ID, IPMI table 5-4 */
  3331. data[1] = 0x03; /* This is for IPMI 1.0. */
  3332. data[2] = 0x20; /* OS Critical Stop, IPMI table 36-3 */
  3333. data[4] = 0x6f; /* Sensor specific, IPMI table 36-1 */
  3334. data[5] = 0xa1; /* Runtime stop OEM bytes 2 & 3. */
  3335. /* Put a few breadcrumbs in. Hopefully later we can add more things
  3336. to make the panic events more useful. */
  3337. if (str) {
  3338. data[3] = str[0];
  3339. data[6] = str[1];
  3340. data[7] = str[2];
  3341. }
  3342. smi_msg.done = dummy_smi_done_handler;
  3343. recv_msg.done = dummy_recv_done_handler;
  3344. /* For every registered interface, send the event. */
  3345. list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
  3346. if (!intf->handlers)
  3347. /* Interface is not ready. */
  3348. continue;
  3349. /* Send the event announcing the panic. */
  3350. intf->handlers->set_run_to_completion(intf->send_info, 1);
  3351. i_ipmi_request(NULL,
  3352. intf,
  3353. &addr,
  3354. 0,
  3355. &msg,
  3356. intf,
  3357. &smi_msg,
  3358. &recv_msg,
  3359. 0,
  3360. intf->channels[0].address,
  3361. intf->channels[0].lun,
  3362. 0, 1); /* Don't retry, and don't wait. */
  3363. }
  3364. #ifdef CONFIG_IPMI_PANIC_STRING
  3365. /* On every interface, dump a bunch of OEM event holding the
  3366. string. */
  3367. if (!str)
  3368. return;
  3369. /* For every registered interface, send the event. */
  3370. list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
  3371. char *p = str;
  3372. struct ipmi_ipmb_addr *ipmb;
  3373. int j;
  3374. if (intf->intf_num == -1)
  3375. /* Interface was not ready yet. */
  3376. continue;
  3377. /*
  3378. * intf_num is used as an marker to tell if the
  3379. * interface is valid. Thus we need a read barrier to
  3380. * make sure data fetched before checking intf_num
  3381. * won't be used.
  3382. */
  3383. smp_rmb();
  3384. /* First job here is to figure out where to send the
  3385. OEM events. There's no way in IPMI to send OEM
  3386. events using an event send command, so we have to
  3387. find the SEL to put them in and stick them in
  3388. there. */
  3389. /* Get capabilities from the get device id. */
  3390. intf->local_sel_device = 0;
  3391. intf->local_event_generator = 0;
  3392. intf->event_receiver = 0;
  3393. /* Request the device info from the local MC. */
  3394. msg.netfn = IPMI_NETFN_APP_REQUEST;
  3395. msg.cmd = IPMI_GET_DEVICE_ID_CMD;
  3396. msg.data = NULL;
  3397. msg.data_len = 0;
  3398. intf->null_user_handler = device_id_fetcher;
  3399. i_ipmi_request(NULL,
  3400. intf,
  3401. &addr,
  3402. 0,
  3403. &msg,
  3404. intf,
  3405. &smi_msg,
  3406. &recv_msg,
  3407. 0,
  3408. intf->channels[0].address,
  3409. intf->channels[0].lun,
  3410. 0, 1); /* Don't retry, and don't wait. */
  3411. if (intf->local_event_generator) {
  3412. /* Request the event receiver from the local MC. */
  3413. msg.netfn = IPMI_NETFN_SENSOR_EVENT_REQUEST;
  3414. msg.cmd = IPMI_GET_EVENT_RECEIVER_CMD;
  3415. msg.data = NULL;
  3416. msg.data_len = 0;
  3417. intf->null_user_handler = event_receiver_fetcher;
  3418. i_ipmi_request(NULL,
  3419. intf,
  3420. &addr,
  3421. 0,
  3422. &msg,
  3423. intf,
  3424. &smi_msg,
  3425. &recv_msg,
  3426. 0,
  3427. intf->channels[0].address,
  3428. intf->channels[0].lun,
  3429. 0, 1); /* no retry, and no wait. */
  3430. }
  3431. intf->null_user_handler = NULL;
  3432. /* Validate the event receiver. The low bit must not
  3433. be 1 (it must be a valid IPMB address), it cannot
  3434. be zero, and it must not be my address. */
  3435. if (((intf->event_receiver & 1) == 0)
  3436. && (intf->event_receiver != 0)
  3437. && (intf->event_receiver != intf->channels[0].address))
  3438. {
  3439. /* The event receiver is valid, send an IPMB
  3440. message. */
  3441. ipmb = (struct ipmi_ipmb_addr *) &addr;
  3442. ipmb->addr_type = IPMI_IPMB_ADDR_TYPE;
  3443. ipmb->channel = 0; /* FIXME - is this right? */
  3444. ipmb->lun = intf->event_receiver_lun;
  3445. ipmb->slave_addr = intf->event_receiver;
  3446. } else if (intf->local_sel_device) {
  3447. /* The event receiver was not valid (or was
  3448. me), but I am an SEL device, just dump it
  3449. in my SEL. */
  3450. si = (struct ipmi_system_interface_addr *) &addr;
  3451. si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  3452. si->channel = IPMI_BMC_CHANNEL;
  3453. si->lun = 0;
  3454. } else
  3455. continue; /* No where to send the event. */
  3456. msg.netfn = IPMI_NETFN_STORAGE_REQUEST; /* Storage. */
  3457. msg.cmd = IPMI_ADD_SEL_ENTRY_CMD;
  3458. msg.data = data;
  3459. msg.data_len = 16;
  3460. j = 0;
  3461. while (*p) {
  3462. int size = strlen(p);
  3463. if (size > 11)
  3464. size = 11;
  3465. data[0] = 0;
  3466. data[1] = 0;
  3467. data[2] = 0xf0; /* OEM event without timestamp. */
  3468. data[3] = intf->channels[0].address;
  3469. data[4] = j++; /* sequence # */
  3470. /* Always give 11 bytes, so strncpy will fill
  3471. it with zeroes for me. */
  3472. strncpy(data+5, p, 11);
  3473. p += size;
  3474. i_ipmi_request(NULL,
  3475. intf,
  3476. &addr,
  3477. 0,
  3478. &msg,
  3479. intf,
  3480. &smi_msg,
  3481. &recv_msg,
  3482. 0,
  3483. intf->channels[0].address,
  3484. intf->channels[0].lun,
  3485. 0, 1); /* no retry, and no wait. */
  3486. }
  3487. }
  3488. #endif /* CONFIG_IPMI_PANIC_STRING */
  3489. }
  3490. #endif /* CONFIG_IPMI_PANIC_EVENT */
  3491. static int has_panicked;
  3492. static int panic_event(struct notifier_block *this,
  3493. unsigned long event,
  3494. void *ptr)
  3495. {
  3496. ipmi_smi_t intf;
  3497. if (has_panicked)
  3498. return NOTIFY_DONE;
  3499. has_panicked = 1;
  3500. /* For every registered interface, set it to run to completion. */
  3501. list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
  3502. if (!intf->handlers)
  3503. /* Interface is not ready. */
  3504. continue;
  3505. intf->handlers->set_run_to_completion(intf->send_info, 1);
  3506. }
  3507. #ifdef CONFIG_IPMI_PANIC_EVENT
  3508. send_panic_events(ptr);
  3509. #endif
  3510. return NOTIFY_DONE;
  3511. }
  3512. static struct notifier_block panic_block = {
  3513. .notifier_call = panic_event,
  3514. .next = NULL,
  3515. .priority = 200 /* priority: INT_MAX >= x >= 0 */
  3516. };
  3517. static int ipmi_init_msghandler(void)
  3518. {
  3519. int rv;
  3520. if (initialized)
  3521. return 0;
  3522. rv = driver_register(&ipmidriver);
  3523. if (rv) {
  3524. printk(KERN_ERR PFX "Could not register IPMI driver\n");
  3525. return rv;
  3526. }
  3527. printk(KERN_INFO "ipmi message handler version "
  3528. IPMI_DRIVER_VERSION "\n");
  3529. #ifdef CONFIG_PROC_FS
  3530. proc_ipmi_root = proc_mkdir("ipmi", NULL);
  3531. if (!proc_ipmi_root) {
  3532. printk(KERN_ERR PFX "Unable to create IPMI proc dir");
  3533. return -ENOMEM;
  3534. }
  3535. proc_ipmi_root->owner = THIS_MODULE;
  3536. #endif /* CONFIG_PROC_FS */
  3537. setup_timer(&ipmi_timer, ipmi_timeout, 0);
  3538. mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES);
  3539. atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
  3540. initialized = 1;
  3541. return 0;
  3542. }
  3543. static __init int ipmi_init_msghandler_mod(void)
  3544. {
  3545. ipmi_init_msghandler();
  3546. return 0;
  3547. }
  3548. static __exit void cleanup_ipmi(void)
  3549. {
  3550. int count;
  3551. if (!initialized)
  3552. return;
  3553. atomic_notifier_chain_unregister(&panic_notifier_list, &panic_block);
  3554. /* This can't be called if any interfaces exist, so no worry about
  3555. shutting down the interfaces. */
  3556. /* Tell the timer to stop, then wait for it to stop. This avoids
  3557. problems with race conditions removing the timer here. */
  3558. atomic_inc(&stop_operation);
  3559. del_timer_sync(&ipmi_timer);
  3560. #ifdef CONFIG_PROC_FS
  3561. remove_proc_entry(proc_ipmi_root->name, NULL);
  3562. #endif /* CONFIG_PROC_FS */
  3563. driver_unregister(&ipmidriver);
  3564. initialized = 0;
  3565. /* Check for buffer leaks. */
  3566. count = atomic_read(&smi_msg_inuse_count);
  3567. if (count != 0)
  3568. printk(KERN_WARNING PFX "SMI message count %d at exit\n",
  3569. count);
  3570. count = atomic_read(&recv_msg_inuse_count);
  3571. if (count != 0)
  3572. printk(KERN_WARNING PFX "recv message count %d at exit\n",
  3573. count);
  3574. }
  3575. module_exit(cleanup_ipmi);
  3576. module_init(ipmi_init_msghandler_mod);
  3577. MODULE_LICENSE("GPL");
  3578. MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
  3579. MODULE_DESCRIPTION("Incoming and outgoing message routing for an IPMI interface.");
  3580. MODULE_VERSION(IPMI_DRIVER_VERSION);
  3581. EXPORT_SYMBOL(ipmi_create_user);
  3582. EXPORT_SYMBOL(ipmi_destroy_user);
  3583. EXPORT_SYMBOL(ipmi_get_version);
  3584. EXPORT_SYMBOL(ipmi_request_settime);
  3585. EXPORT_SYMBOL(ipmi_request_supply_msgs);
  3586. EXPORT_SYMBOL(ipmi_poll_interface);
  3587. EXPORT_SYMBOL(ipmi_register_smi);
  3588. EXPORT_SYMBOL(ipmi_unregister_smi);
  3589. EXPORT_SYMBOL(ipmi_register_for_cmd);
  3590. EXPORT_SYMBOL(ipmi_unregister_for_cmd);
  3591. EXPORT_SYMBOL(ipmi_smi_msg_received);
  3592. EXPORT_SYMBOL(ipmi_smi_watchdog_pretimeout);
  3593. EXPORT_SYMBOL(ipmi_alloc_smi_msg);
  3594. EXPORT_SYMBOL(ipmi_addr_length);
  3595. EXPORT_SYMBOL(ipmi_validate_addr);
  3596. EXPORT_SYMBOL(ipmi_set_gets_events);
  3597. EXPORT_SYMBOL(ipmi_smi_watcher_register);
  3598. EXPORT_SYMBOL(ipmi_smi_watcher_unregister);
  3599. EXPORT_SYMBOL(ipmi_set_my_address);
  3600. EXPORT_SYMBOL(ipmi_get_my_address);
  3601. EXPORT_SYMBOL(ipmi_set_my_LUN);
  3602. EXPORT_SYMBOL(ipmi_get_my_LUN);
  3603. EXPORT_SYMBOL(ipmi_smi_add_proc_entry);
  3604. EXPORT_SYMBOL(ipmi_user_set_run_to_completion);
  3605. EXPORT_SYMBOL(ipmi_free_recv_msg);