mpt2sas_ctl.c 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598
  1. /*
  2. * Management Module Support for MPT (Message Passing Technology) based
  3. * controllers
  4. *
  5. * This code is based on drivers/scsi/mpt2sas/mpt2_ctl.c
  6. * Copyright (C) 2007-2008 LSI Corporation
  7. * (mailto:DL-MPTFusionLinux@lsi.com)
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * NO WARRANTY
  20. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  21. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  22. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  23. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  24. * solely responsible for determining the appropriateness of using and
  25. * distributing the Program and assumes all risks associated with its
  26. * exercise of rights under this Agreement, including but not limited to
  27. * the risks and costs of program errors, damage to or loss of data,
  28. * programs or equipment, and unavailability or interruption of operations.
  29. * DISCLAIMER OF LIABILITY
  30. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. * You should have received a copy of the GNU General Public License
  38. * along with this program; if not, write to the Free Software
  39. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  40. * USA.
  41. */
  42. #include <linux/version.h>
  43. #include <linux/kernel.h>
  44. #include <linux/module.h>
  45. #include <linux/errno.h>
  46. #include <linux/init.h>
  47. #include <linux/slab.h>
  48. #include <linux/types.h>
  49. #include <linux/pci.h>
  50. #include <linux/delay.h>
  51. #include <linux/smp_lock.h>
  52. #include <linux/compat.h>
  53. #include <linux/poll.h>
  54. #include <linux/io.h>
  55. #include <linux/uaccess.h>
  56. #include "mpt2sas_base.h"
  57. #include "mpt2sas_ctl.h"
  58. static struct fasync_struct *async_queue;
  59. static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait);
  60. static int _ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type,
  61. u8 *issue_reset);
  62. /**
  63. * enum block_state - blocking state
  64. * @NON_BLOCKING: non blocking
  65. * @BLOCKING: blocking
  66. *
  67. * These states are for ioctls that need to wait for a response
  68. * from firmware, so they probably require sleep.
  69. */
  70. enum block_state {
  71. NON_BLOCKING,
  72. BLOCKING,
  73. };
  74. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  75. /**
  76. * _ctl_display_some_debug - debug routine
  77. * @ioc: per adapter object
  78. * @smid: system request message index
  79. * @calling_function_name: string pass from calling function
  80. * @mpi_reply: reply message frame
  81. * Context: none.
  82. *
  83. * Function for displaying debug info helpfull when debugging issues
  84. * in this module.
  85. */
  86. static void
  87. _ctl_display_some_debug(struct MPT2SAS_ADAPTER *ioc, u16 smid,
  88. char *calling_function_name, MPI2DefaultReply_t *mpi_reply)
  89. {
  90. Mpi2ConfigRequest_t *mpi_request;
  91. char *desc = NULL;
  92. if (!(ioc->logging_level & MPT_DEBUG_IOCTL))
  93. return;
  94. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  95. switch (mpi_request->Function) {
  96. case MPI2_FUNCTION_SCSI_IO_REQUEST:
  97. {
  98. Mpi2SCSIIORequest_t *scsi_request =
  99. (Mpi2SCSIIORequest_t *)mpi_request;
  100. snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
  101. "scsi_io, cmd(0x%02x), cdb_len(%d)",
  102. scsi_request->CDB.CDB32[0],
  103. le16_to_cpu(scsi_request->IoFlags) & 0xF);
  104. desc = ioc->tmp_string;
  105. break;
  106. }
  107. case MPI2_FUNCTION_SCSI_TASK_MGMT:
  108. desc = "task_mgmt";
  109. break;
  110. case MPI2_FUNCTION_IOC_INIT:
  111. desc = "ioc_init";
  112. break;
  113. case MPI2_FUNCTION_IOC_FACTS:
  114. desc = "ioc_facts";
  115. break;
  116. case MPI2_FUNCTION_CONFIG:
  117. {
  118. Mpi2ConfigRequest_t *config_request =
  119. (Mpi2ConfigRequest_t *)mpi_request;
  120. snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
  121. "config, type(0x%02x), ext_type(0x%02x), number(%d)",
  122. (config_request->Header.PageType &
  123. MPI2_CONFIG_PAGETYPE_MASK), config_request->ExtPageType,
  124. config_request->Header.PageNumber);
  125. desc = ioc->tmp_string;
  126. break;
  127. }
  128. case MPI2_FUNCTION_PORT_FACTS:
  129. desc = "port_facts";
  130. break;
  131. case MPI2_FUNCTION_PORT_ENABLE:
  132. desc = "port_enable";
  133. break;
  134. case MPI2_FUNCTION_EVENT_NOTIFICATION:
  135. desc = "event_notification";
  136. break;
  137. case MPI2_FUNCTION_FW_DOWNLOAD:
  138. desc = "fw_download";
  139. break;
  140. case MPI2_FUNCTION_FW_UPLOAD:
  141. desc = "fw_upload";
  142. break;
  143. case MPI2_FUNCTION_RAID_ACTION:
  144. desc = "raid_action";
  145. break;
  146. case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
  147. {
  148. Mpi2SCSIIORequest_t *scsi_request =
  149. (Mpi2SCSIIORequest_t *)mpi_request;
  150. snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
  151. "raid_pass, cmd(0x%02x), cdb_len(%d)",
  152. scsi_request->CDB.CDB32[0],
  153. le16_to_cpu(scsi_request->IoFlags) & 0xF);
  154. desc = ioc->tmp_string;
  155. break;
  156. }
  157. case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
  158. desc = "sas_iounit_cntl";
  159. break;
  160. case MPI2_FUNCTION_SATA_PASSTHROUGH:
  161. desc = "sata_pass";
  162. break;
  163. case MPI2_FUNCTION_DIAG_BUFFER_POST:
  164. desc = "diag_buffer_post";
  165. break;
  166. case MPI2_FUNCTION_DIAG_RELEASE:
  167. desc = "diag_release";
  168. break;
  169. case MPI2_FUNCTION_SMP_PASSTHROUGH:
  170. desc = "smp_passthrough";
  171. break;
  172. }
  173. if (!desc)
  174. return;
  175. printk(MPT2SAS_DEBUG_FMT "%s: %s, smid(%d)\n",
  176. ioc->name, calling_function_name, desc, smid);
  177. if (!mpi_reply)
  178. return;
  179. if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo)
  180. printk(MPT2SAS_DEBUG_FMT
  181. "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
  182. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  183. le32_to_cpu(mpi_reply->IOCLogInfo));
  184. if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
  185. mpi_request->Function ==
  186. MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
  187. Mpi2SCSIIOReply_t *scsi_reply =
  188. (Mpi2SCSIIOReply_t *)mpi_reply;
  189. if (scsi_reply->SCSIState || scsi_reply->SCSIStatus)
  190. printk(MPT2SAS_DEBUG_FMT
  191. "\tscsi_state(0x%02x), scsi_status"
  192. "(0x%02x)\n", ioc->name,
  193. scsi_reply->SCSIState,
  194. scsi_reply->SCSIStatus);
  195. }
  196. }
  197. #endif
  198. /**
  199. * mpt2sas_ctl_done - ctl module completion routine
  200. * @ioc: per adapter object
  201. * @smid: system request message index
  202. * @VF_ID: virtual function id
  203. * @reply: reply message frame(lower 32bit addr)
  204. * Context: none.
  205. *
  206. * The callback handler when using ioc->ctl_cb_idx.
  207. *
  208. * Return nothing.
  209. */
  210. void
  211. mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
  212. {
  213. MPI2DefaultReply_t *mpi_reply;
  214. if (ioc->ctl_cmds.status == MPT2_CMD_NOT_USED)
  215. return;
  216. if (ioc->ctl_cmds.smid != smid)
  217. return;
  218. ioc->ctl_cmds.status |= MPT2_CMD_COMPLETE;
  219. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  220. if (mpi_reply) {
  221. memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
  222. ioc->ctl_cmds.status |= MPT2_CMD_REPLY_VALID;
  223. }
  224. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  225. _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply);
  226. #endif
  227. ioc->ctl_cmds.status &= ~MPT2_CMD_PENDING;
  228. complete(&ioc->ctl_cmds.done);
  229. }
  230. /**
  231. * _ctl_check_event_type - determines when an event needs logging
  232. * @ioc: per adapter object
  233. * @event: firmware event
  234. *
  235. * The bitmask in ioc->event_type[] indicates which events should be
  236. * be saved in the driver event_log. This bitmask is set by application.
  237. *
  238. * Returns 1 when event should be captured, or zero means no match.
  239. */
  240. static int
  241. _ctl_check_event_type(struct MPT2SAS_ADAPTER *ioc, u16 event)
  242. {
  243. u16 i;
  244. u32 desired_event;
  245. if (event >= 128 || !event || !ioc->event_log)
  246. return 0;
  247. desired_event = (1 << (event % 32));
  248. if (!desired_event)
  249. desired_event = 1;
  250. i = event / 32;
  251. return desired_event & ioc->event_type[i];
  252. }
  253. /**
  254. * mpt2sas_ctl_add_to_event_log - add event
  255. * @ioc: per adapter object
  256. * @mpi_reply: reply message frame
  257. *
  258. * Return nothing.
  259. */
  260. void
  261. mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc,
  262. Mpi2EventNotificationReply_t *mpi_reply)
  263. {
  264. struct MPT2_IOCTL_EVENTS *event_log;
  265. u16 event;
  266. int i;
  267. u32 sz, event_data_sz;
  268. u8 send_aen = 0;
  269. if (!ioc->event_log)
  270. return;
  271. event = le16_to_cpu(mpi_reply->Event);
  272. if (_ctl_check_event_type(ioc, event)) {
  273. /* insert entry into circular event_log */
  274. i = ioc->event_context % MPT2SAS_CTL_EVENT_LOG_SIZE;
  275. event_log = ioc->event_log;
  276. event_log[i].event = event;
  277. event_log[i].context = ioc->event_context++;
  278. event_data_sz = le16_to_cpu(mpi_reply->EventDataLength)*4;
  279. sz = min_t(u32, event_data_sz, MPT2_EVENT_DATA_SIZE);
  280. memset(event_log[i].data, 0, MPT2_EVENT_DATA_SIZE);
  281. memcpy(event_log[i].data, mpi_reply->EventData, sz);
  282. send_aen = 1;
  283. }
  284. /* This aen_event_read_flag flag is set until the
  285. * application has read the event log.
  286. * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
  287. */
  288. if (event == MPI2_EVENT_LOG_ENTRY_ADDED ||
  289. (send_aen && !ioc->aen_event_read_flag)) {
  290. ioc->aen_event_read_flag = 1;
  291. wake_up_interruptible(&ctl_poll_wait);
  292. if (async_queue)
  293. kill_fasync(&async_queue, SIGIO, POLL_IN);
  294. }
  295. }
  296. /**
  297. * mpt2sas_ctl_event_callback - firmware event handler (called at ISR time)
  298. * @ioc: per adapter object
  299. * @VF_ID: virtual function id
  300. * @reply: reply message frame(lower 32bit addr)
  301. * Context: interrupt.
  302. *
  303. * This function merely adds a new work task into ioc->firmware_event_thread.
  304. * The tasks are worked from _firmware_event_work in user context.
  305. *
  306. * Return nothing.
  307. */
  308. void
  309. mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, u32 reply)
  310. {
  311. Mpi2EventNotificationReply_t *mpi_reply;
  312. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  313. mpt2sas_ctl_add_to_event_log(ioc, mpi_reply);
  314. }
  315. /**
  316. * _ctl_verify_adapter - validates ioc_number passed from application
  317. * @ioc: per adapter object
  318. * @iocpp: The ioc pointer is returned in this.
  319. *
  320. * Return (-1) means error, else ioc_number.
  321. */
  322. static int
  323. _ctl_verify_adapter(int ioc_number, struct MPT2SAS_ADAPTER **iocpp)
  324. {
  325. struct MPT2SAS_ADAPTER *ioc;
  326. list_for_each_entry(ioc, &mpt2sas_ioc_list, list) {
  327. if (ioc->id != ioc_number)
  328. continue;
  329. *iocpp = ioc;
  330. return ioc_number;
  331. }
  332. *iocpp = NULL;
  333. return -1;
  334. }
  335. /**
  336. * mpt2sas_ctl_reset_handler - reset callback handler (for ctl)
  337. * @ioc: per adapter object
  338. * @reset_phase: phase
  339. *
  340. * The handler for doing any required cleanup or initialization.
  341. *
  342. * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
  343. * MPT2_IOC_DONE_RESET
  344. */
  345. void
  346. mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
  347. {
  348. int i;
  349. u8 issue_reset;
  350. switch (reset_phase) {
  351. case MPT2_IOC_PRE_RESET:
  352. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  353. "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
  354. for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
  355. if (!(ioc->diag_buffer_status[i] &
  356. MPT2_DIAG_BUFFER_IS_REGISTERED))
  357. continue;
  358. if ((ioc->diag_buffer_status[i] &
  359. MPT2_DIAG_BUFFER_IS_RELEASED))
  360. continue;
  361. _ctl_send_release(ioc, i, &issue_reset);
  362. }
  363. break;
  364. case MPT2_IOC_AFTER_RESET:
  365. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  366. "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
  367. if (ioc->ctl_cmds.status & MPT2_CMD_PENDING) {
  368. ioc->ctl_cmds.status |= MPT2_CMD_RESET;
  369. mpt2sas_base_free_smid(ioc, ioc->ctl_cmds.smid);
  370. complete(&ioc->ctl_cmds.done);
  371. }
  372. break;
  373. case MPT2_IOC_DONE_RESET:
  374. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  375. "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
  376. for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
  377. if (!(ioc->diag_buffer_status[i] &
  378. MPT2_DIAG_BUFFER_IS_REGISTERED))
  379. continue;
  380. if ((ioc->diag_buffer_status[i] &
  381. MPT2_DIAG_BUFFER_IS_RELEASED))
  382. continue;
  383. ioc->diag_buffer_status[i] |=
  384. MPT2_DIAG_BUFFER_IS_DIAG_RESET;
  385. }
  386. break;
  387. }
  388. }
  389. /**
  390. * _ctl_fasync -
  391. * @fd -
  392. * @filep -
  393. * @mode -
  394. *
  395. * Called when application request fasyn callback handler.
  396. */
  397. static int
  398. _ctl_fasync(int fd, struct file *filep, int mode)
  399. {
  400. return fasync_helper(fd, filep, mode, &async_queue);
  401. }
  402. /**
  403. * _ctl_release -
  404. * @inode -
  405. * @filep -
  406. *
  407. * Called when application releases the fasyn callback handler.
  408. */
  409. static int
  410. _ctl_release(struct inode *inode, struct file *filep)
  411. {
  412. return fasync_helper(-1, filep, 0, &async_queue);
  413. }
  414. /**
  415. * _ctl_poll -
  416. * @file -
  417. * @wait -
  418. *
  419. */
  420. static unsigned int
  421. _ctl_poll(struct file *filep, poll_table *wait)
  422. {
  423. struct MPT2SAS_ADAPTER *ioc;
  424. poll_wait(filep, &ctl_poll_wait, wait);
  425. list_for_each_entry(ioc, &mpt2sas_ioc_list, list) {
  426. if (ioc->aen_event_read_flag)
  427. return POLLIN | POLLRDNORM;
  428. }
  429. return 0;
  430. }
  431. /**
  432. * _ctl_set_task_mid - assign an active smid to tm request
  433. * @ioc: per adapter object
  434. * @karg - (struct mpt2_ioctl_command)
  435. * @tm_request - pointer to mf from user space
  436. *
  437. * Returns 0 when an smid if found, else fail.
  438. * during failure, the reply frame is filled.
  439. */
  440. static int
  441. _ctl_set_task_mid(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg,
  442. Mpi2SCSITaskManagementRequest_t *tm_request)
  443. {
  444. u8 found = 0;
  445. u16 i;
  446. u16 handle;
  447. struct scsi_cmnd *scmd;
  448. struct MPT2SAS_DEVICE *priv_data;
  449. unsigned long flags;
  450. Mpi2SCSITaskManagementReply_t *tm_reply;
  451. u32 sz;
  452. u32 lun;
  453. char *desc = NULL;
  454. if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
  455. desc = "abort_task";
  456. else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
  457. desc = "query_task";
  458. else
  459. return 0;
  460. lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN);
  461. handle = le16_to_cpu(tm_request->DevHandle);
  462. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  463. for (i = ioc->request_depth; i && !found; i--) {
  464. scmd = ioc->scsi_lookup[i - 1].scmd;
  465. if (scmd == NULL || scmd->device == NULL ||
  466. scmd->device->hostdata == NULL)
  467. continue;
  468. if (lun != scmd->device->lun)
  469. continue;
  470. priv_data = scmd->device->hostdata;
  471. if (priv_data->sas_target == NULL)
  472. continue;
  473. if (priv_data->sas_target->handle != handle)
  474. continue;
  475. tm_request->TaskMID = cpu_to_le16(ioc->scsi_lookup[i - 1].smid);
  476. found = 1;
  477. }
  478. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  479. if (!found) {
  480. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  481. "handle(0x%04x), lun(%d), no active mid!!\n", ioc->name,
  482. desc, tm_request->DevHandle, lun));
  483. tm_reply = ioc->ctl_cmds.reply;
  484. tm_reply->DevHandle = tm_request->DevHandle;
  485. tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  486. tm_reply->TaskType = tm_request->TaskType;
  487. tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4;
  488. tm_reply->VP_ID = tm_request->VP_ID;
  489. tm_reply->VF_ID = tm_request->VF_ID;
  490. sz = min_t(u32, karg->max_reply_bytes, ioc->reply_sz);
  491. if (copy_to_user(karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply,
  492. sz))
  493. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  494. __LINE__, __func__);
  495. return 1;
  496. }
  497. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  498. "handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->name,
  499. desc, tm_request->DevHandle, lun, tm_request->TaskMID));
  500. return 0;
  501. }
  502. /**
  503. * _ctl_do_mpt_command - main handler for MPT2COMMAND opcode
  504. * @ioc: per adapter object
  505. * @karg - (struct mpt2_ioctl_command)
  506. * @mf - pointer to mf in user space
  507. * @state - NON_BLOCKING or BLOCKING
  508. */
  509. static long
  510. _ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc,
  511. struct mpt2_ioctl_command karg, void __user *mf, enum block_state state)
  512. {
  513. MPI2RequestHeader_t *mpi_request;
  514. MPI2DefaultReply_t *mpi_reply;
  515. u32 ioc_state;
  516. u16 ioc_status;
  517. u16 smid;
  518. unsigned long timeout, timeleft;
  519. u8 issue_reset;
  520. u32 sz;
  521. void *psge;
  522. void *priv_sense = NULL;
  523. void *data_out = NULL;
  524. dma_addr_t data_out_dma;
  525. size_t data_out_sz = 0;
  526. void *data_in = NULL;
  527. dma_addr_t data_in_dma;
  528. size_t data_in_sz = 0;
  529. u32 sgl_flags;
  530. long ret;
  531. u16 wait_state_count;
  532. issue_reset = 0;
  533. if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
  534. return -EAGAIN;
  535. else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
  536. return -ERESTARTSYS;
  537. if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
  538. printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
  539. ioc->name, __func__);
  540. ret = -EAGAIN;
  541. goto out;
  542. }
  543. wait_state_count = 0;
  544. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  545. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  546. if (wait_state_count++ == 10) {
  547. printk(MPT2SAS_ERR_FMT
  548. "%s: failed due to ioc not operational\n",
  549. ioc->name, __func__);
  550. ret = -EFAULT;
  551. goto out;
  552. }
  553. ssleep(1);
  554. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  555. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  556. "operational state(count=%d)\n", ioc->name,
  557. __func__, wait_state_count);
  558. }
  559. if (wait_state_count)
  560. printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
  561. ioc->name, __func__);
  562. smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx);
  563. if (!smid) {
  564. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  565. ioc->name, __func__);
  566. ret = -EAGAIN;
  567. goto out;
  568. }
  569. ret = 0;
  570. ioc->ctl_cmds.status = MPT2_CMD_PENDING;
  571. memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
  572. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  573. ioc->ctl_cmds.smid = smid;
  574. data_out_sz = karg.data_out_size;
  575. data_in_sz = karg.data_in_size;
  576. /* copy in request message frame from user */
  577. if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) {
  578. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, __LINE__,
  579. __func__);
  580. ret = -EFAULT;
  581. mpt2sas_base_free_smid(ioc, smid);
  582. goto out;
  583. }
  584. if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
  585. mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
  586. if (!mpi_request->FunctionDependent1 ||
  587. mpi_request->FunctionDependent1 >
  588. cpu_to_le16(ioc->facts.MaxDevHandle)) {
  589. ret = -EINVAL;
  590. mpt2sas_base_free_smid(ioc, smid);
  591. goto out;
  592. }
  593. }
  594. /* obtain dma-able memory for data transfer */
  595. if (data_out_sz) /* WRITE */ {
  596. data_out = pci_alloc_consistent(ioc->pdev, data_out_sz,
  597. &data_out_dma);
  598. if (!data_out) {
  599. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  600. __LINE__, __func__);
  601. ret = -ENOMEM;
  602. mpt2sas_base_free_smid(ioc, smid);
  603. goto out;
  604. }
  605. if (copy_from_user(data_out, karg.data_out_buf_ptr,
  606. data_out_sz)) {
  607. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  608. __LINE__, __func__);
  609. ret = -EFAULT;
  610. mpt2sas_base_free_smid(ioc, smid);
  611. goto out;
  612. }
  613. }
  614. if (data_in_sz) /* READ */ {
  615. data_in = pci_alloc_consistent(ioc->pdev, data_in_sz,
  616. &data_in_dma);
  617. if (!data_in) {
  618. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  619. __LINE__, __func__);
  620. ret = -ENOMEM;
  621. mpt2sas_base_free_smid(ioc, smid);
  622. goto out;
  623. }
  624. }
  625. /* add scatter gather elements */
  626. psge = (void *)mpi_request + (karg.data_sge_offset*4);
  627. if (!data_out_sz && !data_in_sz) {
  628. mpt2sas_base_build_zero_len_sge(ioc, psge);
  629. } else if (data_out_sz && data_in_sz) {
  630. /* WRITE sgel first */
  631. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  632. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
  633. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  634. ioc->base_add_sg_single(psge, sgl_flags |
  635. data_out_sz, data_out_dma);
  636. /* incr sgel */
  637. psge += ioc->sge_size;
  638. /* READ sgel last */
  639. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  640. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  641. MPI2_SGE_FLAGS_END_OF_LIST);
  642. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  643. ioc->base_add_sg_single(psge, sgl_flags |
  644. data_in_sz, data_in_dma);
  645. } else if (data_out_sz) /* WRITE */ {
  646. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  647. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  648. MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC);
  649. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  650. ioc->base_add_sg_single(psge, sgl_flags |
  651. data_out_sz, data_out_dma);
  652. } else if (data_in_sz) /* READ */ {
  653. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  654. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  655. MPI2_SGE_FLAGS_END_OF_LIST);
  656. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  657. ioc->base_add_sg_single(psge, sgl_flags |
  658. data_in_sz, data_in_dma);
  659. }
  660. /* send command to firmware */
  661. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  662. _ctl_display_some_debug(ioc, smid, "ctl_request", NULL);
  663. #endif
  664. switch (mpi_request->Function) {
  665. case MPI2_FUNCTION_SCSI_IO_REQUEST:
  666. case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
  667. {
  668. Mpi2SCSIIORequest_t *scsiio_request =
  669. (Mpi2SCSIIORequest_t *)mpi_request;
  670. scsiio_request->SenseBufferLowAddress =
  671. (u32)mpt2sas_base_get_sense_buffer_dma(ioc, smid);
  672. priv_sense = mpt2sas_base_get_sense_buffer(ioc, smid);
  673. memset(priv_sense, 0, SCSI_SENSE_BUFFERSIZE);
  674. mpt2sas_base_put_smid_scsi_io(ioc, smid, 0,
  675. le16_to_cpu(mpi_request->FunctionDependent1));
  676. break;
  677. }
  678. case MPI2_FUNCTION_SCSI_TASK_MGMT:
  679. {
  680. Mpi2SCSITaskManagementRequest_t *tm_request =
  681. (Mpi2SCSITaskManagementRequest_t *)mpi_request;
  682. if (tm_request->TaskType ==
  683. MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
  684. tm_request->TaskType ==
  685. MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
  686. if (_ctl_set_task_mid(ioc, &karg, tm_request)) {
  687. mpt2sas_base_free_smid(ioc, smid);
  688. goto out;
  689. }
  690. }
  691. mutex_lock(&ioc->tm_cmds.mutex);
  692. mpt2sas_scsih_set_tm_flag(ioc, le16_to_cpu(
  693. tm_request->DevHandle));
  694. mpt2sas_base_put_smid_hi_priority(ioc, smid,
  695. mpi_request->VF_ID);
  696. break;
  697. }
  698. case MPI2_FUNCTION_SMP_PASSTHROUGH:
  699. {
  700. Mpi2SmpPassthroughRequest_t *smp_request =
  701. (Mpi2SmpPassthroughRequest_t *)mpi_request;
  702. u8 *data;
  703. /* ioc determines which port to use */
  704. smp_request->PhysicalPort = 0xFF;
  705. if (smp_request->PassthroughFlags &
  706. MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE)
  707. data = (u8 *)&smp_request->SGL;
  708. else
  709. data = data_out;
  710. if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) {
  711. ioc->ioc_link_reset_in_progress = 1;
  712. ioc->ignore_loginfos = 1;
  713. }
  714. mpt2sas_base_put_smid_default(ioc, smid, mpi_request->VF_ID);
  715. break;
  716. }
  717. case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
  718. {
  719. Mpi2SasIoUnitControlRequest_t *sasiounit_request =
  720. (Mpi2SasIoUnitControlRequest_t *)mpi_request;
  721. if (sasiounit_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET
  722. || sasiounit_request->Operation ==
  723. MPI2_SAS_OP_PHY_LINK_RESET) {
  724. ioc->ioc_link_reset_in_progress = 1;
  725. ioc->ignore_loginfos = 1;
  726. }
  727. mpt2sas_base_put_smid_default(ioc, smid, mpi_request->VF_ID);
  728. break;
  729. }
  730. default:
  731. mpt2sas_base_put_smid_default(ioc, smid, mpi_request->VF_ID);
  732. break;
  733. }
  734. if (karg.timeout < MPT2_IOCTL_DEFAULT_TIMEOUT)
  735. timeout = MPT2_IOCTL_DEFAULT_TIMEOUT;
  736. else
  737. timeout = karg.timeout;
  738. timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
  739. timeout*HZ);
  740. if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
  741. Mpi2SCSITaskManagementRequest_t *tm_request =
  742. (Mpi2SCSITaskManagementRequest_t *)mpi_request;
  743. mutex_unlock(&ioc->tm_cmds.mutex);
  744. mpt2sas_scsih_clear_tm_flag(ioc, le16_to_cpu(
  745. tm_request->DevHandle));
  746. } else if ((mpi_request->Function == MPI2_FUNCTION_SMP_PASSTHROUGH ||
  747. mpi_request->Function == MPI2_FUNCTION_SAS_IO_UNIT_CONTROL) &&
  748. ioc->ioc_link_reset_in_progress) {
  749. ioc->ioc_link_reset_in_progress = 0;
  750. ioc->ignore_loginfos = 0;
  751. }
  752. if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
  753. printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
  754. __func__);
  755. _debug_dump_mf(mpi_request, karg.data_sge_offset);
  756. if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
  757. issue_reset = 1;
  758. goto issue_host_reset;
  759. }
  760. mpi_reply = ioc->ctl_cmds.reply;
  761. ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
  762. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  763. if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT &&
  764. (ioc->logging_level & MPT_DEBUG_TM)) {
  765. Mpi2SCSITaskManagementReply_t *tm_reply =
  766. (Mpi2SCSITaskManagementReply_t *)mpi_reply;
  767. printk(MPT2SAS_DEBUG_FMT "TASK_MGMT: "
  768. "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
  769. "TerminationCount(0x%08x)\n", ioc->name,
  770. tm_reply->IOCStatus, tm_reply->IOCLogInfo,
  771. tm_reply->TerminationCount);
  772. }
  773. #endif
  774. /* copy out xdata to user */
  775. if (data_in_sz) {
  776. if (copy_to_user(karg.data_in_buf_ptr, data_in,
  777. data_in_sz)) {
  778. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  779. __LINE__, __func__);
  780. ret = -ENODATA;
  781. goto out;
  782. }
  783. }
  784. /* copy out reply message frame to user */
  785. if (karg.max_reply_bytes) {
  786. sz = min_t(u32, karg.max_reply_bytes, ioc->reply_sz);
  787. if (copy_to_user(karg.reply_frame_buf_ptr, ioc->ctl_cmds.reply,
  788. sz)) {
  789. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  790. __LINE__, __func__);
  791. ret = -ENODATA;
  792. goto out;
  793. }
  794. }
  795. /* copy out sense to user */
  796. if (karg.max_sense_bytes && (mpi_request->Function ==
  797. MPI2_FUNCTION_SCSI_IO_REQUEST || mpi_request->Function ==
  798. MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
  799. sz = min_t(u32, karg.max_sense_bytes, SCSI_SENSE_BUFFERSIZE);
  800. if (copy_to_user(karg.sense_data_ptr, priv_sense, sz)) {
  801. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  802. __LINE__, __func__);
  803. ret = -ENODATA;
  804. goto out;
  805. }
  806. }
  807. issue_host_reset:
  808. if (issue_reset) {
  809. if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
  810. mpi_request->Function ==
  811. MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
  812. printk(MPT2SAS_INFO_FMT "issue target reset: handle "
  813. "= (0x%04x)\n", ioc->name,
  814. mpi_request->FunctionDependent1);
  815. mutex_lock(&ioc->tm_cmds.mutex);
  816. mpt2sas_scsih_issue_tm(ioc,
  817. mpi_request->FunctionDependent1, 0,
  818. MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10);
  819. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  820. mutex_unlock(&ioc->tm_cmds.mutex);
  821. } else
  822. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  823. FORCE_BIG_HAMMER);
  824. }
  825. out:
  826. /* free memory associated with sg buffers */
  827. if (data_in)
  828. pci_free_consistent(ioc->pdev, data_in_sz, data_in,
  829. data_in_dma);
  830. if (data_out)
  831. pci_free_consistent(ioc->pdev, data_out_sz, data_out,
  832. data_out_dma);
  833. ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
  834. mutex_unlock(&ioc->ctl_cmds.mutex);
  835. return ret;
  836. }
  837. /**
  838. * _ctl_getiocinfo - main handler for MPT2IOCINFO opcode
  839. * @arg - user space buffer containing ioctl content
  840. */
  841. static long
  842. _ctl_getiocinfo(void __user *arg)
  843. {
  844. struct mpt2_ioctl_iocinfo karg;
  845. struct MPT2SAS_ADAPTER *ioc;
  846. u8 revision;
  847. if (copy_from_user(&karg, arg, sizeof(karg))) {
  848. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  849. __FILE__, __LINE__, __func__);
  850. return -EFAULT;
  851. }
  852. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  853. return -ENODEV;
  854. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
  855. __func__));
  856. memset(&karg, 0 , sizeof(karg));
  857. karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2;
  858. if (ioc->pfacts)
  859. karg.port_number = ioc->pfacts[0].PortNumber;
  860. pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
  861. karg.hw_rev = revision;
  862. karg.pci_id = ioc->pdev->device;
  863. karg.subsystem_device = ioc->pdev->subsystem_device;
  864. karg.subsystem_vendor = ioc->pdev->subsystem_vendor;
  865. karg.pci_information.u.bits.bus = ioc->pdev->bus->number;
  866. karg.pci_information.u.bits.device = PCI_SLOT(ioc->pdev->devfn);
  867. karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn);
  868. karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus);
  869. karg.firmware_version = ioc->facts.FWVersion.Word;
  870. strcpy(karg.driver_version, MPT2SAS_DRIVER_NAME);
  871. strcat(karg.driver_version, "-");
  872. strcat(karg.driver_version, MPT2SAS_DRIVER_VERSION);
  873. karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
  874. if (copy_to_user(arg, &karg, sizeof(karg))) {
  875. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  876. __FILE__, __LINE__, __func__);
  877. return -EFAULT;
  878. }
  879. return 0;
  880. }
  881. /**
  882. * _ctl_eventquery - main handler for MPT2EVENTQUERY opcode
  883. * @arg - user space buffer containing ioctl content
  884. */
  885. static long
  886. _ctl_eventquery(void __user *arg)
  887. {
  888. struct mpt2_ioctl_eventquery karg;
  889. struct MPT2SAS_ADAPTER *ioc;
  890. if (copy_from_user(&karg, arg, sizeof(karg))) {
  891. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  892. __FILE__, __LINE__, __func__);
  893. return -EFAULT;
  894. }
  895. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  896. return -ENODEV;
  897. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
  898. __func__));
  899. karg.event_entries = MPT2SAS_CTL_EVENT_LOG_SIZE;
  900. memcpy(karg.event_types, ioc->event_type,
  901. MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
  902. if (copy_to_user(arg, &karg, sizeof(karg))) {
  903. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  904. __FILE__, __LINE__, __func__);
  905. return -EFAULT;
  906. }
  907. return 0;
  908. }
  909. /**
  910. * _ctl_eventenable - main handler for MPT2EVENTENABLE opcode
  911. * @arg - user space buffer containing ioctl content
  912. */
  913. static long
  914. _ctl_eventenable(void __user *arg)
  915. {
  916. struct mpt2_ioctl_eventenable karg;
  917. struct MPT2SAS_ADAPTER *ioc;
  918. if (copy_from_user(&karg, arg, sizeof(karg))) {
  919. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  920. __FILE__, __LINE__, __func__);
  921. return -EFAULT;
  922. }
  923. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  924. return -ENODEV;
  925. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
  926. __func__));
  927. if (ioc->event_log)
  928. return 0;
  929. memcpy(ioc->event_type, karg.event_types,
  930. MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
  931. mpt2sas_base_validate_event_type(ioc, ioc->event_type);
  932. /* initialize event_log */
  933. ioc->event_context = 0;
  934. ioc->aen_event_read_flag = 0;
  935. ioc->event_log = kcalloc(MPT2SAS_CTL_EVENT_LOG_SIZE,
  936. sizeof(struct MPT2_IOCTL_EVENTS), GFP_KERNEL);
  937. if (!ioc->event_log) {
  938. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  939. __FILE__, __LINE__, __func__);
  940. return -ENOMEM;
  941. }
  942. return 0;
  943. }
  944. /**
  945. * _ctl_eventreport - main handler for MPT2EVENTREPORT opcode
  946. * @arg - user space buffer containing ioctl content
  947. */
  948. static long
  949. _ctl_eventreport(void __user *arg)
  950. {
  951. struct mpt2_ioctl_eventreport karg;
  952. struct MPT2SAS_ADAPTER *ioc;
  953. u32 number_bytes, max_events, max;
  954. struct mpt2_ioctl_eventreport __user *uarg = arg;
  955. if (copy_from_user(&karg, arg, sizeof(karg))) {
  956. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  957. __FILE__, __LINE__, __func__);
  958. return -EFAULT;
  959. }
  960. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  961. return -ENODEV;
  962. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
  963. __func__));
  964. number_bytes = karg.hdr.max_data_size -
  965. sizeof(struct mpt2_ioctl_header);
  966. max_events = number_bytes/sizeof(struct MPT2_IOCTL_EVENTS);
  967. max = min_t(u32, MPT2SAS_CTL_EVENT_LOG_SIZE, max_events);
  968. /* If fewer than 1 event is requested, there must have
  969. * been some type of error.
  970. */
  971. if (!max || !ioc->event_log)
  972. return -ENODATA;
  973. number_bytes = max * sizeof(struct MPT2_IOCTL_EVENTS);
  974. if (copy_to_user(uarg->event_data, ioc->event_log, number_bytes)) {
  975. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  976. __FILE__, __LINE__, __func__);
  977. return -EFAULT;
  978. }
  979. /* reset flag so SIGIO can restart */
  980. ioc->aen_event_read_flag = 0;
  981. return 0;
  982. }
  983. /**
  984. * _ctl_do_reset - main handler for MPT2HARDRESET opcode
  985. * @arg - user space buffer containing ioctl content
  986. */
  987. static long
  988. _ctl_do_reset(void __user *arg)
  989. {
  990. struct mpt2_ioctl_diag_reset karg;
  991. struct MPT2SAS_ADAPTER *ioc;
  992. int retval;
  993. if (copy_from_user(&karg, arg, sizeof(karg))) {
  994. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  995. __FILE__, __LINE__, __func__);
  996. return -EFAULT;
  997. }
  998. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  999. return -ENODEV;
  1000. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
  1001. __func__));
  1002. retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1003. FORCE_BIG_HAMMER);
  1004. printk(MPT2SAS_INFO_FMT "host reset: %s\n",
  1005. ioc->name, ((!retval) ? "SUCCESS" : "FAILED"));
  1006. return 0;
  1007. }
  1008. /**
  1009. * _ctl_btdh_search_sas_device - searching for sas device
  1010. * @ioc: per adapter object
  1011. * @btdh: btdh ioctl payload
  1012. */
  1013. static int
  1014. _ctl_btdh_search_sas_device(struct MPT2SAS_ADAPTER *ioc,
  1015. struct mpt2_ioctl_btdh_mapping *btdh)
  1016. {
  1017. struct _sas_device *sas_device;
  1018. unsigned long flags;
  1019. int rc = 0;
  1020. if (list_empty(&ioc->sas_device_list))
  1021. return rc;
  1022. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1023. list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
  1024. if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
  1025. btdh->handle == sas_device->handle) {
  1026. btdh->bus = sas_device->channel;
  1027. btdh->id = sas_device->id;
  1028. rc = 1;
  1029. goto out;
  1030. } else if (btdh->bus == sas_device->channel && btdh->id ==
  1031. sas_device->id && btdh->handle == 0xFFFF) {
  1032. btdh->handle = sas_device->handle;
  1033. rc = 1;
  1034. goto out;
  1035. }
  1036. }
  1037. out:
  1038. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1039. return rc;
  1040. }
  1041. /**
  1042. * _ctl_btdh_search_raid_device - searching for raid device
  1043. * @ioc: per adapter object
  1044. * @btdh: btdh ioctl payload
  1045. */
  1046. static int
  1047. _ctl_btdh_search_raid_device(struct MPT2SAS_ADAPTER *ioc,
  1048. struct mpt2_ioctl_btdh_mapping *btdh)
  1049. {
  1050. struct _raid_device *raid_device;
  1051. unsigned long flags;
  1052. int rc = 0;
  1053. if (list_empty(&ioc->raid_device_list))
  1054. return rc;
  1055. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1056. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  1057. if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
  1058. btdh->handle == raid_device->handle) {
  1059. btdh->bus = raid_device->channel;
  1060. btdh->id = raid_device->id;
  1061. rc = 1;
  1062. goto out;
  1063. } else if (btdh->bus == raid_device->channel && btdh->id ==
  1064. raid_device->id && btdh->handle == 0xFFFF) {
  1065. btdh->handle = raid_device->handle;
  1066. rc = 1;
  1067. goto out;
  1068. }
  1069. }
  1070. out:
  1071. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1072. return rc;
  1073. }
  1074. /**
  1075. * _ctl_btdh_mapping - main handler for MPT2BTDHMAPPING opcode
  1076. * @arg - user space buffer containing ioctl content
  1077. */
  1078. static long
  1079. _ctl_btdh_mapping(void __user *arg)
  1080. {
  1081. struct mpt2_ioctl_btdh_mapping karg;
  1082. struct MPT2SAS_ADAPTER *ioc;
  1083. int rc;
  1084. if (copy_from_user(&karg, arg, sizeof(karg))) {
  1085. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  1086. __FILE__, __LINE__, __func__);
  1087. return -EFAULT;
  1088. }
  1089. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  1090. return -ENODEV;
  1091. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
  1092. __func__));
  1093. rc = _ctl_btdh_search_sas_device(ioc, &karg);
  1094. if (!rc)
  1095. _ctl_btdh_search_raid_device(ioc, &karg);
  1096. if (copy_to_user(arg, &karg, sizeof(karg))) {
  1097. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  1098. __FILE__, __LINE__, __func__);
  1099. return -EFAULT;
  1100. }
  1101. return 0;
  1102. }
  1103. /**
  1104. * _ctl_diag_capability - return diag buffer capability
  1105. * @ioc: per adapter object
  1106. * @buffer_type: specifies either TRACE or SNAPSHOT
  1107. *
  1108. * returns 1 when diag buffer support is enabled in firmware
  1109. */
  1110. static u8
  1111. _ctl_diag_capability(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type)
  1112. {
  1113. u8 rc = 0;
  1114. switch (buffer_type) {
  1115. case MPI2_DIAG_BUF_TYPE_TRACE:
  1116. if (ioc->facts.IOCCapabilities &
  1117. MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER)
  1118. rc = 1;
  1119. break;
  1120. case MPI2_DIAG_BUF_TYPE_SNAPSHOT:
  1121. if (ioc->facts.IOCCapabilities &
  1122. MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER)
  1123. rc = 1;
  1124. break;
  1125. }
  1126. return rc;
  1127. }
  1128. /**
  1129. * _ctl_diag_register - application register with driver
  1130. * @arg - user space buffer containing ioctl content
  1131. * @state - NON_BLOCKING or BLOCKING
  1132. *
  1133. * This will allow the driver to setup any required buffers that will be
  1134. * needed by firmware to communicate with the driver.
  1135. */
  1136. static long
  1137. _ctl_diag_register(void __user *arg, enum block_state state)
  1138. {
  1139. struct mpt2_diag_register karg;
  1140. struct MPT2SAS_ADAPTER *ioc;
  1141. int rc, i;
  1142. void *request_data = NULL;
  1143. dma_addr_t request_data_dma;
  1144. u32 request_data_sz = 0;
  1145. Mpi2DiagBufferPostRequest_t *mpi_request;
  1146. Mpi2DiagBufferPostReply_t *mpi_reply;
  1147. u8 buffer_type;
  1148. unsigned long timeleft;
  1149. u16 smid;
  1150. u16 ioc_status;
  1151. u8 issue_reset = 0;
  1152. if (copy_from_user(&karg, arg, sizeof(karg))) {
  1153. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  1154. __FILE__, __LINE__, __func__);
  1155. return -EFAULT;
  1156. }
  1157. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  1158. return -ENODEV;
  1159. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
  1160. __func__));
  1161. buffer_type = karg.buffer_type;
  1162. if (!_ctl_diag_capability(ioc, buffer_type)) {
  1163. printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
  1164. "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
  1165. return -EPERM;
  1166. }
  1167. if (ioc->diag_buffer_status[buffer_type] &
  1168. MPT2_DIAG_BUFFER_IS_REGISTERED) {
  1169. printk(MPT2SAS_ERR_FMT "%s: already has a registered "
  1170. "buffer for buffer_type(0x%02x)\n", ioc->name, __func__,
  1171. buffer_type);
  1172. return -EINVAL;
  1173. }
  1174. if (karg.requested_buffer_size % 4) {
  1175. printk(MPT2SAS_ERR_FMT "%s: the requested_buffer_size "
  1176. "is not 4 byte aligned\n", ioc->name, __func__);
  1177. return -EINVAL;
  1178. }
  1179. if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
  1180. return -EAGAIN;
  1181. else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
  1182. return -ERESTARTSYS;
  1183. if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
  1184. printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
  1185. ioc->name, __func__);
  1186. rc = -EAGAIN;
  1187. goto out;
  1188. }
  1189. smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx);
  1190. if (!smid) {
  1191. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1192. ioc->name, __func__);
  1193. rc = -EAGAIN;
  1194. goto out;
  1195. }
  1196. rc = 0;
  1197. ioc->ctl_cmds.status = MPT2_CMD_PENDING;
  1198. memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
  1199. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1200. ioc->ctl_cmds.smid = smid;
  1201. request_data = ioc->diag_buffer[buffer_type];
  1202. request_data_sz = karg.requested_buffer_size;
  1203. ioc->unique_id[buffer_type] = karg.unique_id;
  1204. ioc->diag_buffer_status[buffer_type] = 0;
  1205. memcpy(ioc->product_specific[buffer_type], karg.product_specific,
  1206. MPT2_PRODUCT_SPECIFIC_DWORDS);
  1207. ioc->diagnostic_flags[buffer_type] = karg.diagnostic_flags;
  1208. if (request_data) {
  1209. request_data_dma = ioc->diag_buffer_dma[buffer_type];
  1210. if (request_data_sz != ioc->diag_buffer_sz[buffer_type]) {
  1211. pci_free_consistent(ioc->pdev,
  1212. ioc->diag_buffer_sz[buffer_type],
  1213. request_data, request_data_dma);
  1214. request_data = NULL;
  1215. }
  1216. }
  1217. if (request_data == NULL) {
  1218. ioc->diag_buffer_sz[buffer_type] = 0;
  1219. ioc->diag_buffer_dma[buffer_type] = 0;
  1220. request_data = pci_alloc_consistent(
  1221. ioc->pdev, request_data_sz, &request_data_dma);
  1222. if (request_data == NULL) {
  1223. printk(MPT2SAS_ERR_FMT "%s: failed allocating memory"
  1224. " for diag buffers, requested size(%d)\n",
  1225. ioc->name, __func__, request_data_sz);
  1226. mpt2sas_base_free_smid(ioc, smid);
  1227. return -ENOMEM;
  1228. }
  1229. ioc->diag_buffer[buffer_type] = request_data;
  1230. ioc->diag_buffer_sz[buffer_type] = request_data_sz;
  1231. ioc->diag_buffer_dma[buffer_type] = request_data_dma;
  1232. }
  1233. mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
  1234. mpi_request->BufferType = karg.buffer_type;
  1235. mpi_request->Flags = cpu_to_le32(karg.diagnostic_flags);
  1236. mpi_request->BufferAddress = cpu_to_le64(request_data_dma);
  1237. mpi_request->BufferLength = cpu_to_le32(request_data_sz);
  1238. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: diag_buffer(0x%p), "
  1239. "dma(0x%llx), sz(%d)\n", ioc->name, __func__, request_data,
  1240. (unsigned long long)request_data_dma, mpi_request->BufferLength));
  1241. for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++)
  1242. mpi_request->ProductSpecific[i] =
  1243. cpu_to_le32(ioc->product_specific[buffer_type][i]);
  1244. mpt2sas_base_put_smid_default(ioc, smid, mpi_request->VF_ID);
  1245. timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
  1246. MPT2_IOCTL_DEFAULT_TIMEOUT*HZ);
  1247. if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
  1248. printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
  1249. __func__);
  1250. _debug_dump_mf(mpi_request,
  1251. sizeof(Mpi2DiagBufferPostRequest_t)/4);
  1252. if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
  1253. issue_reset = 1;
  1254. goto issue_host_reset;
  1255. }
  1256. /* process the completed Reply Message Frame */
  1257. if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) {
  1258. printk(MPT2SAS_ERR_FMT "%s: no reply message\n",
  1259. ioc->name, __func__);
  1260. rc = -EFAULT;
  1261. goto out;
  1262. }
  1263. mpi_reply = ioc->ctl_cmds.reply;
  1264. ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
  1265. if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
  1266. ioc->diag_buffer_status[buffer_type] |=
  1267. MPT2_DIAG_BUFFER_IS_REGISTERED;
  1268. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: success\n",
  1269. ioc->name, __func__));
  1270. } else {
  1271. printk(MPT2SAS_DEBUG_FMT "%s: ioc_status(0x%04x) "
  1272. "log_info(0x%08x)\n", ioc->name, __func__,
  1273. ioc_status, mpi_reply->IOCLogInfo);
  1274. rc = -EFAULT;
  1275. }
  1276. issue_host_reset:
  1277. if (issue_reset)
  1278. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1279. FORCE_BIG_HAMMER);
  1280. out:
  1281. if (rc && request_data)
  1282. pci_free_consistent(ioc->pdev, request_data_sz,
  1283. request_data, request_data_dma);
  1284. ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
  1285. mutex_unlock(&ioc->ctl_cmds.mutex);
  1286. return rc;
  1287. }
  1288. /**
  1289. * _ctl_diag_unregister - application unregister with driver
  1290. * @arg - user space buffer containing ioctl content
  1291. *
  1292. * This will allow the driver to cleanup any memory allocated for diag
  1293. * messages and to free up any resources.
  1294. */
  1295. static long
  1296. _ctl_diag_unregister(void __user *arg)
  1297. {
  1298. struct mpt2_diag_unregister karg;
  1299. struct MPT2SAS_ADAPTER *ioc;
  1300. void *request_data;
  1301. dma_addr_t request_data_dma;
  1302. u32 request_data_sz;
  1303. u8 buffer_type;
  1304. if (copy_from_user(&karg, arg, sizeof(karg))) {
  1305. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  1306. __FILE__, __LINE__, __func__);
  1307. return -EFAULT;
  1308. }
  1309. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  1310. return -ENODEV;
  1311. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
  1312. __func__));
  1313. buffer_type = karg.unique_id & 0x000000ff;
  1314. if (!_ctl_diag_capability(ioc, buffer_type)) {
  1315. printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
  1316. "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
  1317. return -EPERM;
  1318. }
  1319. if ((ioc->diag_buffer_status[buffer_type] &
  1320. MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
  1321. printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
  1322. "registered\n", ioc->name, __func__, buffer_type);
  1323. return -EINVAL;
  1324. }
  1325. if ((ioc->diag_buffer_status[buffer_type] &
  1326. MPT2_DIAG_BUFFER_IS_RELEASED) == 0) {
  1327. printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) has not been "
  1328. "released\n", ioc->name, __func__, buffer_type);
  1329. return -EINVAL;
  1330. }
  1331. if (karg.unique_id != ioc->unique_id[buffer_type]) {
  1332. printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
  1333. "registered\n", ioc->name, __func__, karg.unique_id);
  1334. return -EINVAL;
  1335. }
  1336. request_data = ioc->diag_buffer[buffer_type];
  1337. if (!request_data) {
  1338. printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for "
  1339. "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
  1340. return -ENOMEM;
  1341. }
  1342. request_data_sz = ioc->diag_buffer_sz[buffer_type];
  1343. request_data_dma = ioc->diag_buffer_dma[buffer_type];
  1344. pci_free_consistent(ioc->pdev, request_data_sz,
  1345. request_data, request_data_dma);
  1346. ioc->diag_buffer[buffer_type] = NULL;
  1347. ioc->diag_buffer_status[buffer_type] = 0;
  1348. return 0;
  1349. }
  1350. /**
  1351. * _ctl_diag_query - query relevant info associated with diag buffers
  1352. * @arg - user space buffer containing ioctl content
  1353. *
  1354. * The application will send only buffer_type and unique_id. Driver will
  1355. * inspect unique_id first, if valid, fill in all the info. If unique_id is
  1356. * 0x00, the driver will return info specified by Buffer Type.
  1357. */
  1358. static long
  1359. _ctl_diag_query(void __user *arg)
  1360. {
  1361. struct mpt2_diag_query karg;
  1362. struct MPT2SAS_ADAPTER *ioc;
  1363. void *request_data;
  1364. int i;
  1365. u8 buffer_type;
  1366. if (copy_from_user(&karg, arg, sizeof(karg))) {
  1367. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  1368. __FILE__, __LINE__, __func__);
  1369. return -EFAULT;
  1370. }
  1371. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  1372. return -ENODEV;
  1373. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
  1374. __func__));
  1375. karg.application_flags = 0;
  1376. buffer_type = karg.buffer_type;
  1377. if (!_ctl_diag_capability(ioc, buffer_type)) {
  1378. printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
  1379. "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
  1380. return -EPERM;
  1381. }
  1382. if ((ioc->diag_buffer_status[buffer_type] &
  1383. MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
  1384. printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
  1385. "registered\n", ioc->name, __func__, buffer_type);
  1386. return -EINVAL;
  1387. }
  1388. if (karg.unique_id & 0xffffff00) {
  1389. if (karg.unique_id != ioc->unique_id[buffer_type]) {
  1390. printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
  1391. "registered\n", ioc->name, __func__,
  1392. karg.unique_id);
  1393. return -EINVAL;
  1394. }
  1395. }
  1396. request_data = ioc->diag_buffer[buffer_type];
  1397. if (!request_data) {
  1398. printk(MPT2SAS_ERR_FMT "%s: doesn't have buffer for "
  1399. "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
  1400. return -ENOMEM;
  1401. }
  1402. if (ioc->diag_buffer_status[buffer_type] & MPT2_DIAG_BUFFER_IS_RELEASED)
  1403. karg.application_flags = (MPT2_APP_FLAGS_APP_OWNED |
  1404. MPT2_APP_FLAGS_BUFFER_VALID);
  1405. else
  1406. karg.application_flags = (MPT2_APP_FLAGS_APP_OWNED |
  1407. MPT2_APP_FLAGS_BUFFER_VALID |
  1408. MPT2_APP_FLAGS_FW_BUFFER_ACCESS);
  1409. for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++)
  1410. karg.product_specific[i] =
  1411. ioc->product_specific[buffer_type][i];
  1412. karg.total_buffer_size = ioc->diag_buffer_sz[buffer_type];
  1413. karg.driver_added_buffer_size = 0;
  1414. karg.unique_id = ioc->unique_id[buffer_type];
  1415. karg.diagnostic_flags = ioc->diagnostic_flags[buffer_type];
  1416. if (copy_to_user(arg, &karg, sizeof(struct mpt2_diag_query))) {
  1417. printk(MPT2SAS_ERR_FMT "%s: unable to write mpt2_diag_query "
  1418. "data @ %p\n", ioc->name, __func__, arg);
  1419. return -EFAULT;
  1420. }
  1421. return 0;
  1422. }
  1423. /**
  1424. * _ctl_send_release - Diag Release Message
  1425. * @ioc: per adapter object
  1426. * @buffer_type - specifies either TRACE or SNAPSHOT
  1427. * @issue_reset - specifies whether host reset is required.
  1428. *
  1429. */
  1430. static int
  1431. _ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type, u8 *issue_reset)
  1432. {
  1433. Mpi2DiagReleaseRequest_t *mpi_request;
  1434. Mpi2DiagReleaseReply_t *mpi_reply;
  1435. u16 smid;
  1436. u16 ioc_status;
  1437. u32 ioc_state;
  1438. int rc;
  1439. unsigned long timeleft;
  1440. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
  1441. __func__));
  1442. rc = 0;
  1443. *issue_reset = 0;
  1444. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1445. if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  1446. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  1447. "skipping due to FAULT state\n", ioc->name,
  1448. __func__));
  1449. rc = -EAGAIN;
  1450. goto out;
  1451. }
  1452. if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
  1453. printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
  1454. ioc->name, __func__);
  1455. rc = -EAGAIN;
  1456. goto out;
  1457. }
  1458. smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx);
  1459. if (!smid) {
  1460. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1461. ioc->name, __func__);
  1462. rc = -EAGAIN;
  1463. goto out;
  1464. }
  1465. ioc->ctl_cmds.status = MPT2_CMD_PENDING;
  1466. memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
  1467. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1468. ioc->ctl_cmds.smid = smid;
  1469. mpi_request->Function = MPI2_FUNCTION_DIAG_RELEASE;
  1470. mpi_request->BufferType = buffer_type;
  1471. mpt2sas_base_put_smid_default(ioc, smid, mpi_request->VF_ID);
  1472. timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
  1473. MPT2_IOCTL_DEFAULT_TIMEOUT*HZ);
  1474. if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
  1475. printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
  1476. __func__);
  1477. _debug_dump_mf(mpi_request,
  1478. sizeof(Mpi2DiagReleaseRequest_t)/4);
  1479. if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
  1480. *issue_reset = 1;
  1481. rc = -EFAULT;
  1482. goto out;
  1483. }
  1484. /* process the completed Reply Message Frame */
  1485. if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) {
  1486. printk(MPT2SAS_ERR_FMT "%s: no reply message\n",
  1487. ioc->name, __func__);
  1488. rc = -EFAULT;
  1489. goto out;
  1490. }
  1491. mpi_reply = ioc->ctl_cmds.reply;
  1492. ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
  1493. if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
  1494. ioc->diag_buffer_status[buffer_type] |=
  1495. MPT2_DIAG_BUFFER_IS_RELEASED;
  1496. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: success\n",
  1497. ioc->name, __func__));
  1498. } else {
  1499. printk(MPT2SAS_DEBUG_FMT "%s: ioc_status(0x%04x) "
  1500. "log_info(0x%08x)\n", ioc->name, __func__,
  1501. ioc_status, mpi_reply->IOCLogInfo);
  1502. rc = -EFAULT;
  1503. }
  1504. out:
  1505. ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
  1506. return rc;
  1507. }
  1508. /**
  1509. * _ctl_diag_release - request to send Diag Release Message to firmware
  1510. * @arg - user space buffer containing ioctl content
  1511. * @state - NON_BLOCKING or BLOCKING
  1512. *
  1513. * This allows ownership of the specified buffer to returned to the driver,
  1514. * allowing an application to read the buffer without fear that firmware is
  1515. * overwritting information in the buffer.
  1516. */
  1517. static long
  1518. _ctl_diag_release(void __user *arg, enum block_state state)
  1519. {
  1520. struct mpt2_diag_release karg;
  1521. struct MPT2SAS_ADAPTER *ioc;
  1522. void *request_data;
  1523. int rc;
  1524. u8 buffer_type;
  1525. u8 issue_reset = 0;
  1526. if (copy_from_user(&karg, arg, sizeof(karg))) {
  1527. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  1528. __FILE__, __LINE__, __func__);
  1529. return -EFAULT;
  1530. }
  1531. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  1532. return -ENODEV;
  1533. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
  1534. __func__));
  1535. buffer_type = karg.unique_id & 0x000000ff;
  1536. if (!_ctl_diag_capability(ioc, buffer_type)) {
  1537. printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
  1538. "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
  1539. return -EPERM;
  1540. }
  1541. if ((ioc->diag_buffer_status[buffer_type] &
  1542. MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
  1543. printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
  1544. "registered\n", ioc->name, __func__, buffer_type);
  1545. return -EINVAL;
  1546. }
  1547. if (karg.unique_id != ioc->unique_id[buffer_type]) {
  1548. printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
  1549. "registered\n", ioc->name, __func__, karg.unique_id);
  1550. return -EINVAL;
  1551. }
  1552. if (ioc->diag_buffer_status[buffer_type] &
  1553. MPT2_DIAG_BUFFER_IS_RELEASED) {
  1554. printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) "
  1555. "is already released\n", ioc->name, __func__,
  1556. buffer_type);
  1557. return 0;
  1558. }
  1559. request_data = ioc->diag_buffer[buffer_type];
  1560. if (!request_data) {
  1561. printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for "
  1562. "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
  1563. return -ENOMEM;
  1564. }
  1565. /* buffers were released by due to host reset */
  1566. if ((ioc->diag_buffer_status[buffer_type] &
  1567. MPT2_DIAG_BUFFER_IS_DIAG_RESET)) {
  1568. ioc->diag_buffer_status[buffer_type] |=
  1569. MPT2_DIAG_BUFFER_IS_RELEASED;
  1570. ioc->diag_buffer_status[buffer_type] &=
  1571. ~MPT2_DIAG_BUFFER_IS_DIAG_RESET;
  1572. printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) "
  1573. "was released due to host reset\n", ioc->name, __func__,
  1574. buffer_type);
  1575. return 0;
  1576. }
  1577. if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
  1578. return -EAGAIN;
  1579. else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
  1580. return -ERESTARTSYS;
  1581. rc = _ctl_send_release(ioc, buffer_type, &issue_reset);
  1582. if (issue_reset)
  1583. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1584. FORCE_BIG_HAMMER);
  1585. mutex_unlock(&ioc->ctl_cmds.mutex);
  1586. return rc;
  1587. }
  1588. /**
  1589. * _ctl_diag_read_buffer - request for copy of the diag buffer
  1590. * @arg - user space buffer containing ioctl content
  1591. * @state - NON_BLOCKING or BLOCKING
  1592. */
  1593. static long
  1594. _ctl_diag_read_buffer(void __user *arg, enum block_state state)
  1595. {
  1596. struct mpt2_diag_read_buffer karg;
  1597. struct mpt2_diag_read_buffer __user *uarg = arg;
  1598. struct MPT2SAS_ADAPTER *ioc;
  1599. void *request_data, *diag_data;
  1600. Mpi2DiagBufferPostRequest_t *mpi_request;
  1601. Mpi2DiagBufferPostReply_t *mpi_reply;
  1602. int rc, i;
  1603. u8 buffer_type;
  1604. unsigned long timeleft;
  1605. u16 smid;
  1606. u16 ioc_status;
  1607. u8 issue_reset = 0;
  1608. if (copy_from_user(&karg, arg, sizeof(karg))) {
  1609. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  1610. __FILE__, __LINE__, __func__);
  1611. return -EFAULT;
  1612. }
  1613. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
  1614. return -ENODEV;
  1615. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
  1616. __func__));
  1617. buffer_type = karg.unique_id & 0x000000ff;
  1618. if (!_ctl_diag_capability(ioc, buffer_type)) {
  1619. printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
  1620. "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
  1621. return -EPERM;
  1622. }
  1623. if (karg.unique_id != ioc->unique_id[buffer_type]) {
  1624. printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
  1625. "registered\n", ioc->name, __func__, karg.unique_id);
  1626. return -EINVAL;
  1627. }
  1628. request_data = ioc->diag_buffer[buffer_type];
  1629. if (!request_data) {
  1630. printk(MPT2SAS_ERR_FMT "%s: doesn't have buffer for "
  1631. "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
  1632. return -ENOMEM;
  1633. }
  1634. if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) {
  1635. printk(MPT2SAS_ERR_FMT "%s: either the starting_offset "
  1636. "or bytes_to_read are not 4 byte aligned\n", ioc->name,
  1637. __func__);
  1638. return -EINVAL;
  1639. }
  1640. diag_data = (void *)(request_data + karg.starting_offset);
  1641. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: diag_buffer(%p), "
  1642. "offset(%d), sz(%d)\n", ioc->name, __func__,
  1643. diag_data, karg.starting_offset, karg.bytes_to_read));
  1644. if (copy_to_user((void __user *)uarg->diagnostic_data,
  1645. diag_data, karg.bytes_to_read)) {
  1646. printk(MPT2SAS_ERR_FMT "%s: Unable to write "
  1647. "mpt_diag_read_buffer_t data @ %p\n", ioc->name,
  1648. __func__, diag_data);
  1649. return -EFAULT;
  1650. }
  1651. if ((karg.flags & MPT2_FLAGS_REREGISTER) == 0)
  1652. return 0;
  1653. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: Reregister "
  1654. "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type));
  1655. if ((ioc->diag_buffer_status[buffer_type] &
  1656. MPT2_DIAG_BUFFER_IS_RELEASED) == 0) {
  1657. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  1658. "buffer_type(0x%02x) is still registered\n", ioc->name,
  1659. __func__, buffer_type));
  1660. return 0;
  1661. }
  1662. /* Get a free request frame and save the message context.
  1663. */
  1664. if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
  1665. return -EAGAIN;
  1666. else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
  1667. return -ERESTARTSYS;
  1668. if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
  1669. printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
  1670. ioc->name, __func__);
  1671. rc = -EAGAIN;
  1672. goto out;
  1673. }
  1674. smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx);
  1675. if (!smid) {
  1676. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1677. ioc->name, __func__);
  1678. rc = -EAGAIN;
  1679. goto out;
  1680. }
  1681. rc = 0;
  1682. ioc->ctl_cmds.status = MPT2_CMD_PENDING;
  1683. memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
  1684. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1685. ioc->ctl_cmds.smid = smid;
  1686. mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
  1687. mpi_request->BufferType = buffer_type;
  1688. mpi_request->BufferLength =
  1689. cpu_to_le32(ioc->diag_buffer_sz[buffer_type]);
  1690. mpi_request->BufferAddress =
  1691. cpu_to_le64(ioc->diag_buffer_dma[buffer_type]);
  1692. for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++)
  1693. mpi_request->ProductSpecific[i] =
  1694. cpu_to_le32(ioc->product_specific[buffer_type][i]);
  1695. mpt2sas_base_put_smid_default(ioc, smid, mpi_request->VF_ID);
  1696. timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
  1697. MPT2_IOCTL_DEFAULT_TIMEOUT*HZ);
  1698. if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
  1699. printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
  1700. __func__);
  1701. _debug_dump_mf(mpi_request,
  1702. sizeof(Mpi2DiagBufferPostRequest_t)/4);
  1703. if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
  1704. issue_reset = 1;
  1705. goto issue_host_reset;
  1706. }
  1707. /* process the completed Reply Message Frame */
  1708. if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) {
  1709. printk(MPT2SAS_ERR_FMT "%s: no reply message\n",
  1710. ioc->name, __func__);
  1711. rc = -EFAULT;
  1712. goto out;
  1713. }
  1714. mpi_reply = ioc->ctl_cmds.reply;
  1715. ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
  1716. if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
  1717. ioc->diag_buffer_status[buffer_type] |=
  1718. MPT2_DIAG_BUFFER_IS_REGISTERED;
  1719. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: success\n",
  1720. ioc->name, __func__));
  1721. } else {
  1722. printk(MPT2SAS_DEBUG_FMT "%s: ioc_status(0x%04x) "
  1723. "log_info(0x%08x)\n", ioc->name, __func__,
  1724. ioc_status, mpi_reply->IOCLogInfo);
  1725. rc = -EFAULT;
  1726. }
  1727. issue_host_reset:
  1728. if (issue_reset)
  1729. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1730. FORCE_BIG_HAMMER);
  1731. out:
  1732. ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
  1733. mutex_unlock(&ioc->ctl_cmds.mutex);
  1734. return rc;
  1735. }
  1736. /**
  1737. * _ctl_ioctl_main - main ioctl entry point
  1738. * @file - (struct file)
  1739. * @cmd - ioctl opcode
  1740. * @arg -
  1741. */
  1742. static long
  1743. _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg)
  1744. {
  1745. enum block_state state;
  1746. long ret = -EINVAL;
  1747. unsigned long flags;
  1748. state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING :
  1749. BLOCKING;
  1750. switch (cmd) {
  1751. case MPT2IOCINFO:
  1752. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_iocinfo))
  1753. ret = _ctl_getiocinfo(arg);
  1754. break;
  1755. case MPT2COMMAND:
  1756. {
  1757. struct mpt2_ioctl_command karg;
  1758. struct mpt2_ioctl_command __user *uarg;
  1759. struct MPT2SAS_ADAPTER *ioc;
  1760. if (copy_from_user(&karg, arg, sizeof(karg))) {
  1761. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  1762. __FILE__, __LINE__, __func__);
  1763. return -EFAULT;
  1764. }
  1765. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 ||
  1766. !ioc)
  1767. return -ENODEV;
  1768. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  1769. if (ioc->shost_recovery) {
  1770. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock,
  1771. flags);
  1772. return -EAGAIN;
  1773. }
  1774. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  1775. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_command)) {
  1776. uarg = arg;
  1777. ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf, state);
  1778. }
  1779. break;
  1780. }
  1781. case MPT2EVENTQUERY:
  1782. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventquery))
  1783. ret = _ctl_eventquery(arg);
  1784. break;
  1785. case MPT2EVENTENABLE:
  1786. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventenable))
  1787. ret = _ctl_eventenable(arg);
  1788. break;
  1789. case MPT2EVENTREPORT:
  1790. ret = _ctl_eventreport(arg);
  1791. break;
  1792. case MPT2HARDRESET:
  1793. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_diag_reset))
  1794. ret = _ctl_do_reset(arg);
  1795. break;
  1796. case MPT2BTDHMAPPING:
  1797. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_btdh_mapping))
  1798. ret = _ctl_btdh_mapping(arg);
  1799. break;
  1800. case MPT2DIAGREGISTER:
  1801. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_register))
  1802. ret = _ctl_diag_register(arg, state);
  1803. break;
  1804. case MPT2DIAGUNREGISTER:
  1805. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_unregister))
  1806. ret = _ctl_diag_unregister(arg);
  1807. break;
  1808. case MPT2DIAGQUERY:
  1809. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_query))
  1810. ret = _ctl_diag_query(arg);
  1811. break;
  1812. case MPT2DIAGRELEASE:
  1813. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_release))
  1814. ret = _ctl_diag_release(arg, state);
  1815. break;
  1816. case MPT2DIAGREADBUFFER:
  1817. if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_read_buffer))
  1818. ret = _ctl_diag_read_buffer(arg, state);
  1819. break;
  1820. default:
  1821. {
  1822. struct mpt2_ioctl_command karg;
  1823. struct MPT2SAS_ADAPTER *ioc;
  1824. if (copy_from_user(&karg, arg, sizeof(karg))) {
  1825. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  1826. __FILE__, __LINE__, __func__);
  1827. return -EFAULT;
  1828. }
  1829. if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 ||
  1830. !ioc)
  1831. return -ENODEV;
  1832. dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  1833. "unsupported ioctl opcode(0x%08x)\n", ioc->name, cmd));
  1834. break;
  1835. }
  1836. }
  1837. return ret;
  1838. }
  1839. /**
  1840. * _ctl_ioctl - main ioctl entry point (unlocked)
  1841. * @file - (struct file)
  1842. * @cmd - ioctl opcode
  1843. * @arg -
  1844. */
  1845. static long
  1846. _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  1847. {
  1848. long ret;
  1849. lock_kernel();
  1850. ret = _ctl_ioctl_main(file, cmd, (void __user *)arg);
  1851. unlock_kernel();
  1852. return ret;
  1853. }
  1854. #ifdef CONFIG_COMPAT
  1855. /**
  1856. * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
  1857. * @file - (struct file)
  1858. * @cmd - ioctl opcode
  1859. * @arg - (struct mpt2_ioctl_command32)
  1860. *
  1861. * MPT2COMMAND32 - Handle 32bit applications running on 64bit os.
  1862. */
  1863. static long
  1864. _ctl_compat_mpt_command(struct file *file, unsigned cmd, unsigned long arg)
  1865. {
  1866. struct mpt2_ioctl_command32 karg32;
  1867. struct mpt2_ioctl_command32 __user *uarg;
  1868. struct mpt2_ioctl_command karg;
  1869. struct MPT2SAS_ADAPTER *ioc;
  1870. enum block_state state;
  1871. unsigned long flags;
  1872. if (_IOC_SIZE(cmd) != sizeof(struct mpt2_ioctl_command32))
  1873. return -EINVAL;
  1874. uarg = (struct mpt2_ioctl_command32 __user *) arg;
  1875. if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32))) {
  1876. printk(KERN_ERR "failure at %s:%d/%s()!\n",
  1877. __FILE__, __LINE__, __func__);
  1878. return -EFAULT;
  1879. }
  1880. if (_ctl_verify_adapter(karg32.hdr.ioc_number, &ioc) == -1 || !ioc)
  1881. return -ENODEV;
  1882. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  1883. if (ioc->shost_recovery) {
  1884. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock,
  1885. flags);
  1886. return -EAGAIN;
  1887. }
  1888. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  1889. memset(&karg, 0, sizeof(struct mpt2_ioctl_command));
  1890. karg.hdr.ioc_number = karg32.hdr.ioc_number;
  1891. karg.hdr.port_number = karg32.hdr.port_number;
  1892. karg.hdr.max_data_size = karg32.hdr.max_data_size;
  1893. karg.timeout = karg32.timeout;
  1894. karg.max_reply_bytes = karg32.max_reply_bytes;
  1895. karg.data_in_size = karg32.data_in_size;
  1896. karg.data_out_size = karg32.data_out_size;
  1897. karg.max_sense_bytes = karg32.max_sense_bytes;
  1898. karg.data_sge_offset = karg32.data_sge_offset;
  1899. memcpy(&karg.reply_frame_buf_ptr, &karg32.reply_frame_buf_ptr,
  1900. sizeof(uint32_t));
  1901. memcpy(&karg.data_in_buf_ptr, &karg32.data_in_buf_ptr,
  1902. sizeof(uint32_t));
  1903. memcpy(&karg.data_out_buf_ptr, &karg32.data_out_buf_ptr,
  1904. sizeof(uint32_t));
  1905. memcpy(&karg.sense_data_ptr, &karg32.sense_data_ptr,
  1906. sizeof(uint32_t));
  1907. state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
  1908. return _ctl_do_mpt_command(ioc, karg, &uarg->mf, state);
  1909. }
  1910. /**
  1911. * _ctl_ioctl_compat - main ioctl entry point (compat)
  1912. * @file -
  1913. * @cmd -
  1914. * @arg -
  1915. *
  1916. * This routine handles 32 bit applications in 64bit os.
  1917. */
  1918. static long
  1919. _ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
  1920. {
  1921. long ret;
  1922. lock_kernel();
  1923. if (cmd == MPT2COMMAND32)
  1924. ret = _ctl_compat_mpt_command(file, cmd, arg);
  1925. else
  1926. ret = _ctl_ioctl_main(file, cmd, (void __user *)arg);
  1927. unlock_kernel();
  1928. return ret;
  1929. }
  1930. #endif
  1931. /* scsi host attributes */
  1932. /**
  1933. * _ctl_version_fw_show - firmware version
  1934. * @cdev - pointer to embedded class device
  1935. * @buf - the buffer returned
  1936. *
  1937. * A sysfs 'read-only' shost attribute.
  1938. */
  1939. static ssize_t
  1940. _ctl_version_fw_show(struct device *cdev, struct device_attribute *attr,
  1941. char *buf)
  1942. {
  1943. struct Scsi_Host *shost = class_to_shost(cdev);
  1944. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1945. return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
  1946. (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
  1947. (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
  1948. (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
  1949. ioc->facts.FWVersion.Word & 0x000000FF);
  1950. }
  1951. static DEVICE_ATTR(version_fw, S_IRUGO, _ctl_version_fw_show, NULL);
  1952. /**
  1953. * _ctl_version_bios_show - bios version
  1954. * @cdev - pointer to embedded class device
  1955. * @buf - the buffer returned
  1956. *
  1957. * A sysfs 'read-only' shost attribute.
  1958. */
  1959. static ssize_t
  1960. _ctl_version_bios_show(struct device *cdev, struct device_attribute *attr,
  1961. char *buf)
  1962. {
  1963. struct Scsi_Host *shost = class_to_shost(cdev);
  1964. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1965. u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
  1966. return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
  1967. (version & 0xFF000000) >> 24,
  1968. (version & 0x00FF0000) >> 16,
  1969. (version & 0x0000FF00) >> 8,
  1970. version & 0x000000FF);
  1971. }
  1972. static DEVICE_ATTR(version_bios, S_IRUGO, _ctl_version_bios_show, NULL);
  1973. /**
  1974. * _ctl_version_mpi_show - MPI (message passing interface) version
  1975. * @cdev - pointer to embedded class device
  1976. * @buf - the buffer returned
  1977. *
  1978. * A sysfs 'read-only' shost attribute.
  1979. */
  1980. static ssize_t
  1981. _ctl_version_mpi_show(struct device *cdev, struct device_attribute *attr,
  1982. char *buf)
  1983. {
  1984. struct Scsi_Host *shost = class_to_shost(cdev);
  1985. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1986. return snprintf(buf, PAGE_SIZE, "%03x.%02x\n",
  1987. ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8);
  1988. }
  1989. static DEVICE_ATTR(version_mpi, S_IRUGO, _ctl_version_mpi_show, NULL);
  1990. /**
  1991. * _ctl_version_product_show - product name
  1992. * @cdev - pointer to embedded class device
  1993. * @buf - the buffer returned
  1994. *
  1995. * A sysfs 'read-only' shost attribute.
  1996. */
  1997. static ssize_t
  1998. _ctl_version_product_show(struct device *cdev, struct device_attribute *attr,
  1999. char *buf)
  2000. {
  2001. struct Scsi_Host *shost = class_to_shost(cdev);
  2002. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2003. return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName);
  2004. }
  2005. static DEVICE_ATTR(version_product, S_IRUGO,
  2006. _ctl_version_product_show, NULL);
  2007. /**
  2008. * _ctl_version_nvdata_persistent_show - ndvata persistent version
  2009. * @cdev - pointer to embedded class device
  2010. * @buf - the buffer returned
  2011. *
  2012. * A sysfs 'read-only' shost attribute.
  2013. */
  2014. static ssize_t
  2015. _ctl_version_nvdata_persistent_show(struct device *cdev,
  2016. struct device_attribute *attr, char *buf)
  2017. {
  2018. struct Scsi_Host *shost = class_to_shost(cdev);
  2019. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2020. return snprintf(buf, PAGE_SIZE, "%02xh\n",
  2021. le16_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
  2022. }
  2023. static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
  2024. _ctl_version_nvdata_persistent_show, NULL);
  2025. /**
  2026. * _ctl_version_nvdata_default_show - nvdata default version
  2027. * @cdev - pointer to embedded class device
  2028. * @buf - the buffer returned
  2029. *
  2030. * A sysfs 'read-only' shost attribute.
  2031. */
  2032. static ssize_t
  2033. _ctl_version_nvdata_default_show(struct device *cdev,
  2034. struct device_attribute *attr, char *buf)
  2035. {
  2036. struct Scsi_Host *shost = class_to_shost(cdev);
  2037. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2038. return snprintf(buf, PAGE_SIZE, "%02xh\n",
  2039. le16_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
  2040. }
  2041. static DEVICE_ATTR(version_nvdata_default, S_IRUGO,
  2042. _ctl_version_nvdata_default_show, NULL);
  2043. /**
  2044. * _ctl_board_name_show - board name
  2045. * @cdev - pointer to embedded class device
  2046. * @buf - the buffer returned
  2047. *
  2048. * A sysfs 'read-only' shost attribute.
  2049. */
  2050. static ssize_t
  2051. _ctl_board_name_show(struct device *cdev, struct device_attribute *attr,
  2052. char *buf)
  2053. {
  2054. struct Scsi_Host *shost = class_to_shost(cdev);
  2055. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2056. return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName);
  2057. }
  2058. static DEVICE_ATTR(board_name, S_IRUGO, _ctl_board_name_show, NULL);
  2059. /**
  2060. * _ctl_board_assembly_show - board assembly name
  2061. * @cdev - pointer to embedded class device
  2062. * @buf - the buffer returned
  2063. *
  2064. * A sysfs 'read-only' shost attribute.
  2065. */
  2066. static ssize_t
  2067. _ctl_board_assembly_show(struct device *cdev, struct device_attribute *attr,
  2068. char *buf)
  2069. {
  2070. struct Scsi_Host *shost = class_to_shost(cdev);
  2071. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2072. return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly);
  2073. }
  2074. static DEVICE_ATTR(board_assembly, S_IRUGO,
  2075. _ctl_board_assembly_show, NULL);
  2076. /**
  2077. * _ctl_board_tracer_show - board tracer number
  2078. * @cdev - pointer to embedded class device
  2079. * @buf - the buffer returned
  2080. *
  2081. * A sysfs 'read-only' shost attribute.
  2082. */
  2083. static ssize_t
  2084. _ctl_board_tracer_show(struct device *cdev, struct device_attribute *attr,
  2085. char *buf)
  2086. {
  2087. struct Scsi_Host *shost = class_to_shost(cdev);
  2088. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2089. return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber);
  2090. }
  2091. static DEVICE_ATTR(board_tracer, S_IRUGO,
  2092. _ctl_board_tracer_show, NULL);
  2093. /**
  2094. * _ctl_io_delay_show - io missing delay
  2095. * @cdev - pointer to embedded class device
  2096. * @buf - the buffer returned
  2097. *
  2098. * This is for firmware implemention for deboucing device
  2099. * removal events.
  2100. *
  2101. * A sysfs 'read-only' shost attribute.
  2102. */
  2103. static ssize_t
  2104. _ctl_io_delay_show(struct device *cdev, struct device_attribute *attr,
  2105. char *buf)
  2106. {
  2107. struct Scsi_Host *shost = class_to_shost(cdev);
  2108. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2109. return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
  2110. }
  2111. static DEVICE_ATTR(io_delay, S_IRUGO,
  2112. _ctl_io_delay_show, NULL);
  2113. /**
  2114. * _ctl_device_delay_show - device missing delay
  2115. * @cdev - pointer to embedded class device
  2116. * @buf - the buffer returned
  2117. *
  2118. * This is for firmware implemention for deboucing device
  2119. * removal events.
  2120. *
  2121. * A sysfs 'read-only' shost attribute.
  2122. */
  2123. static ssize_t
  2124. _ctl_device_delay_show(struct device *cdev, struct device_attribute *attr,
  2125. char *buf)
  2126. {
  2127. struct Scsi_Host *shost = class_to_shost(cdev);
  2128. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2129. return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
  2130. }
  2131. static DEVICE_ATTR(device_delay, S_IRUGO,
  2132. _ctl_device_delay_show, NULL);
  2133. /**
  2134. * _ctl_fw_queue_depth_show - global credits
  2135. * @cdev - pointer to embedded class device
  2136. * @buf - the buffer returned
  2137. *
  2138. * This is firmware queue depth limit
  2139. *
  2140. * A sysfs 'read-only' shost attribute.
  2141. */
  2142. static ssize_t
  2143. _ctl_fw_queue_depth_show(struct device *cdev, struct device_attribute *attr,
  2144. char *buf)
  2145. {
  2146. struct Scsi_Host *shost = class_to_shost(cdev);
  2147. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2148. return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit);
  2149. }
  2150. static DEVICE_ATTR(fw_queue_depth, S_IRUGO,
  2151. _ctl_fw_queue_depth_show, NULL);
  2152. /**
  2153. * _ctl_sas_address_show - sas address
  2154. * @cdev - pointer to embedded class device
  2155. * @buf - the buffer returned
  2156. *
  2157. * This is the controller sas address
  2158. *
  2159. * A sysfs 'read-only' shost attribute.
  2160. */
  2161. static ssize_t
  2162. _ctl_host_sas_address_show(struct device *cdev, struct device_attribute *attr,
  2163. char *buf)
  2164. {
  2165. struct Scsi_Host *shost = class_to_shost(cdev);
  2166. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2167. return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
  2168. (unsigned long long)ioc->sas_hba.sas_address);
  2169. }
  2170. static DEVICE_ATTR(host_sas_address, S_IRUGO,
  2171. _ctl_host_sas_address_show, NULL);
  2172. /**
  2173. * _ctl_logging_level_show - logging level
  2174. * @cdev - pointer to embedded class device
  2175. * @buf - the buffer returned
  2176. *
  2177. * A sysfs 'read/write' shost attribute.
  2178. */
  2179. static ssize_t
  2180. _ctl_logging_level_show(struct device *cdev, struct device_attribute *attr,
  2181. char *buf)
  2182. {
  2183. struct Scsi_Host *shost = class_to_shost(cdev);
  2184. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2185. return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level);
  2186. }
  2187. static ssize_t
  2188. _ctl_logging_level_store(struct device *cdev, struct device_attribute *attr,
  2189. const char *buf, size_t count)
  2190. {
  2191. struct Scsi_Host *shost = class_to_shost(cdev);
  2192. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  2193. int val = 0;
  2194. if (sscanf(buf, "%x", &val) != 1)
  2195. return -EINVAL;
  2196. ioc->logging_level = val;
  2197. printk(MPT2SAS_INFO_FMT "logging_level=%08xh\n", ioc->name,
  2198. ioc->logging_level);
  2199. return strlen(buf);
  2200. }
  2201. static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
  2202. _ctl_logging_level_show, _ctl_logging_level_store);
  2203. struct device_attribute *mpt2sas_host_attrs[] = {
  2204. &dev_attr_version_fw,
  2205. &dev_attr_version_bios,
  2206. &dev_attr_version_mpi,
  2207. &dev_attr_version_product,
  2208. &dev_attr_version_nvdata_persistent,
  2209. &dev_attr_version_nvdata_default,
  2210. &dev_attr_board_name,
  2211. &dev_attr_board_assembly,
  2212. &dev_attr_board_tracer,
  2213. &dev_attr_io_delay,
  2214. &dev_attr_device_delay,
  2215. &dev_attr_logging_level,
  2216. &dev_attr_fw_queue_depth,
  2217. &dev_attr_host_sas_address,
  2218. NULL,
  2219. };
  2220. /* device attributes */
  2221. /**
  2222. * _ctl_device_sas_address_show - sas address
  2223. * @cdev - pointer to embedded class device
  2224. * @buf - the buffer returned
  2225. *
  2226. * This is the sas address for the target
  2227. *
  2228. * A sysfs 'read-only' shost attribute.
  2229. */
  2230. static ssize_t
  2231. _ctl_device_sas_address_show(struct device *dev, struct device_attribute *attr,
  2232. char *buf)
  2233. {
  2234. struct scsi_device *sdev = to_scsi_device(dev);
  2235. struct MPT2SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
  2236. return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
  2237. (unsigned long long)sas_device_priv_data->sas_target->sas_address);
  2238. }
  2239. static DEVICE_ATTR(sas_address, S_IRUGO, _ctl_device_sas_address_show, NULL);
  2240. /**
  2241. * _ctl_device_handle_show - device handle
  2242. * @cdev - pointer to embedded class device
  2243. * @buf - the buffer returned
  2244. *
  2245. * This is the firmware assigned device handle
  2246. *
  2247. * A sysfs 'read-only' shost attribute.
  2248. */
  2249. static ssize_t
  2250. _ctl_device_handle_show(struct device *dev, struct device_attribute *attr,
  2251. char *buf)
  2252. {
  2253. struct scsi_device *sdev = to_scsi_device(dev);
  2254. struct MPT2SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
  2255. return snprintf(buf, PAGE_SIZE, "0x%04x\n",
  2256. sas_device_priv_data->sas_target->handle);
  2257. }
  2258. static DEVICE_ATTR(sas_device_handle, S_IRUGO, _ctl_device_handle_show, NULL);
  2259. struct device_attribute *mpt2sas_dev_attrs[] = {
  2260. &dev_attr_sas_address,
  2261. &dev_attr_sas_device_handle,
  2262. NULL,
  2263. };
  2264. static const struct file_operations ctl_fops = {
  2265. .owner = THIS_MODULE,
  2266. .unlocked_ioctl = _ctl_ioctl,
  2267. .release = _ctl_release,
  2268. .poll = _ctl_poll,
  2269. .fasync = _ctl_fasync,
  2270. #ifdef CONFIG_COMPAT
  2271. .compat_ioctl = _ctl_ioctl_compat,
  2272. #endif
  2273. };
  2274. static struct miscdevice ctl_dev = {
  2275. .minor = MPT2SAS_MINOR,
  2276. .name = MPT2SAS_DEV_NAME,
  2277. .fops = &ctl_fops,
  2278. };
  2279. /**
  2280. * mpt2sas_ctl_init - main entry point for ctl.
  2281. *
  2282. */
  2283. void
  2284. mpt2sas_ctl_init(void)
  2285. {
  2286. async_queue = NULL;
  2287. if (misc_register(&ctl_dev) < 0)
  2288. printk(KERN_ERR "%s can't register misc device [minor=%d]\n",
  2289. MPT2SAS_DRIVER_NAME, MPT2SAS_MINOR);
  2290. init_waitqueue_head(&ctl_poll_wait);
  2291. }
  2292. /**
  2293. * mpt2sas_ctl_exit - exit point for ctl
  2294. *
  2295. */
  2296. void
  2297. mpt2sas_ctl_exit(void)
  2298. {
  2299. struct MPT2SAS_ADAPTER *ioc;
  2300. int i;
  2301. list_for_each_entry(ioc, &mpt2sas_ioc_list, list) {
  2302. /* free memory associated to diag buffers */
  2303. for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
  2304. if (!ioc->diag_buffer[i])
  2305. continue;
  2306. pci_free_consistent(ioc->pdev, ioc->diag_buffer_sz[i],
  2307. ioc->diag_buffer[i], ioc->diag_buffer_dma[i]);
  2308. ioc->diag_buffer[i] = NULL;
  2309. ioc->diag_buffer_status[i] = 0;
  2310. }
  2311. kfree(ioc->event_log);
  2312. }
  2313. misc_deregister(&ctl_dev);
  2314. }