mpt2sas_ctl.c 72 KB

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