mptctl.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080
  1. /*
  2. * linux/drivers/message/fusion/mptctl.c
  3. * mpt Ioctl driver.
  4. * For use with LSI PCI chip/adapters
  5. * running LSI Fusion MPT (Message Passing Technology) firmware.
  6. *
  7. * Copyright (c) 1999-2008 LSI Corporation
  8. * (mailto:DL-MPTFusionLinux@lsi.com)
  9. *
  10. */
  11. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  12. /*
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; version 2 of the License.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. NO WARRANTY
  21. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  22. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  23. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  24. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  25. solely responsible for determining the appropriateness of using and
  26. distributing the Program and assumes all risks associated with its
  27. exercise of rights under this Agreement, including but not limited to
  28. the risks and costs of program errors, damage to or loss of data,
  29. programs or equipment, and unavailability or interruption of operations.
  30. DISCLAIMER OF LIABILITY
  31. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  32. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  34. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  35. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  36. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  37. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  38. You should have received a copy of the GNU General Public License
  39. along with this program; if not, write to the Free Software
  40. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  41. */
  42. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  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> /* for mdelay */
  51. #include <linux/miscdevice.h>
  52. #include <linux/mutex.h>
  53. #include <linux/compat.h>
  54. #include <asm/io.h>
  55. #include <asm/uaccess.h>
  56. #include <scsi/scsi.h>
  57. #include <scsi/scsi_cmnd.h>
  58. #include <scsi/scsi_device.h>
  59. #include <scsi/scsi_host.h>
  60. #include <scsi/scsi_tcq.h>
  61. #define COPYRIGHT "Copyright (c) 1999-2008 LSI Corporation"
  62. #define MODULEAUTHOR "LSI Corporation"
  63. #include "mptbase.h"
  64. #include "mptctl.h"
  65. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  66. #define my_NAME "Fusion MPT misc device (ioctl) driver"
  67. #define my_VERSION MPT_LINUX_VERSION_COMMON
  68. #define MYNAM "mptctl"
  69. MODULE_AUTHOR(MODULEAUTHOR);
  70. MODULE_DESCRIPTION(my_NAME);
  71. MODULE_LICENSE("GPL");
  72. MODULE_VERSION(my_VERSION);
  73. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  74. static DEFINE_MUTEX(mpctl_mutex);
  75. static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS;
  76. static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS;
  77. static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait );
  78. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  79. struct buflist {
  80. u8 *kptr;
  81. int len;
  82. };
  83. /*
  84. * Function prototypes. Called from OS entry point mptctl_ioctl.
  85. * arg contents specific to function.
  86. */
  87. static int mptctl_fw_download(unsigned long arg);
  88. static int mptctl_getiocinfo(unsigned long arg, unsigned int cmd);
  89. static int mptctl_gettargetinfo(unsigned long arg);
  90. static int mptctl_readtest(unsigned long arg);
  91. static int mptctl_mpt_command(unsigned long arg);
  92. static int mptctl_eventquery(unsigned long arg);
  93. static int mptctl_eventenable(unsigned long arg);
  94. static int mptctl_eventreport(unsigned long arg);
  95. static int mptctl_replace_fw(unsigned long arg);
  96. static int mptctl_do_reset(unsigned long arg);
  97. static int mptctl_hp_hostinfo(unsigned long arg, unsigned int cmd);
  98. static int mptctl_hp_targetinfo(unsigned long arg);
  99. static int mptctl_probe(struct pci_dev *, const struct pci_device_id *);
  100. static void mptctl_remove(struct pci_dev *);
  101. #ifdef CONFIG_COMPAT
  102. static long compat_mpctl_ioctl(struct file *f, unsigned cmd, unsigned long arg);
  103. #endif
  104. /*
  105. * Private function calls.
  106. */
  107. static int mptctl_do_mpt_command(struct mpt_ioctl_command karg, void __user *mfPtr);
  108. static int mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen);
  109. static MptSge_t *kbuf_alloc_2_sgl(int bytes, u32 dir, int sge_offset, int *frags,
  110. struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc);
  111. static void kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma,
  112. struct buflist *buflist, MPT_ADAPTER *ioc);
  113. /*
  114. * Reset Handler cleanup function
  115. */
  116. static int mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase);
  117. /*
  118. * Event Handler function
  119. */
  120. static int mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
  121. static struct fasync_struct *async_queue=NULL;
  122. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  123. /*
  124. * Scatter gather list (SGL) sizes and limits...
  125. */
  126. //#define MAX_SCSI_FRAGS 9
  127. #define MAX_FRAGS_SPILL1 9
  128. #define MAX_FRAGS_SPILL2 15
  129. #define FRAGS_PER_BUCKET (MAX_FRAGS_SPILL2 + 1)
  130. //#define MAX_CHAIN_FRAGS 64
  131. //#define MAX_CHAIN_FRAGS (15+15+15+16)
  132. #define MAX_CHAIN_FRAGS (4 * MAX_FRAGS_SPILL2 + 1)
  133. // Define max sg LIST bytes ( == (#frags + #chains) * 8 bytes each)
  134. // Works out to: 592d bytes! (9+1)*8 + 4*(15+1)*8
  135. // ^----------------- 80 + 512
  136. #define MAX_SGL_BYTES ((MAX_FRAGS_SPILL1 + 1 + (4 * FRAGS_PER_BUCKET)) * 8)
  137. /* linux only seems to ever give 128kB MAX contiguous (GFP_USER) mem bytes */
  138. #define MAX_KMALLOC_SZ (128*1024)
  139. #define MPT_IOCTL_DEFAULT_TIMEOUT 10 /* Default timeout value (seconds) */
  140. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  141. /**
  142. * mptctl_syscall_down - Down the MPT adapter syscall semaphore.
  143. * @ioc: Pointer to MPT adapter
  144. * @nonblock: boolean, non-zero if O_NONBLOCK is set
  145. *
  146. * All of the ioctl commands can potentially sleep, which is illegal
  147. * with a spinlock held, thus we perform mutual exclusion here.
  148. *
  149. * Returns negative errno on error, or zero for success.
  150. */
  151. static inline int
  152. mptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock)
  153. {
  154. int rc = 0;
  155. if (nonblock) {
  156. if (!mutex_trylock(&ioc->ioctl_cmds.mutex))
  157. rc = -EAGAIN;
  158. } else {
  159. if (mutex_lock_interruptible(&ioc->ioctl_cmds.mutex))
  160. rc = -ERESTARTSYS;
  161. }
  162. return rc;
  163. }
  164. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  165. /*
  166. * This is the callback for any message we have posted. The message itself
  167. * will be returned to the message pool when we return from the IRQ
  168. *
  169. * This runs in irq context so be short and sweet.
  170. */
  171. static int
  172. mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
  173. {
  174. char *sense_data;
  175. int req_index;
  176. int sz;
  177. if (!req)
  178. return 0;
  179. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "completing mpi function "
  180. "(0x%02X), req=%p, reply=%p\n", ioc->name, req->u.hdr.Function,
  181. req, reply));
  182. /*
  183. * Handling continuation of the same reply. Processing the first
  184. * reply, and eating the other replys that come later.
  185. */
  186. if (ioc->ioctl_cmds.msg_context != req->u.hdr.MsgContext)
  187. goto out_continuation;
  188. ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  189. if (!reply)
  190. goto out;
  191. ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
  192. sz = min(ioc->reply_sz, 4*reply->u.reply.MsgLength);
  193. memcpy(ioc->ioctl_cmds.reply, reply, sz);
  194. if (reply->u.reply.IOCStatus || reply->u.reply.IOCLogInfo)
  195. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  196. "iocstatus (0x%04X), loginfo (0x%08X)\n", ioc->name,
  197. le16_to_cpu(reply->u.reply.IOCStatus),
  198. le32_to_cpu(reply->u.reply.IOCLogInfo)));
  199. if ((req->u.hdr.Function == MPI_FUNCTION_SCSI_IO_REQUEST) ||
  200. (req->u.hdr.Function ==
  201. MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
  202. if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState)
  203. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  204. "scsi_status (0x%02x), scsi_state (0x%02x), "
  205. "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name,
  206. reply->u.sreply.SCSIStatus,
  207. reply->u.sreply.SCSIState,
  208. le16_to_cpu(reply->u.sreply.TaskTag),
  209. le32_to_cpu(reply->u.sreply.TransferCount)));
  210. if (reply->u.sreply.SCSIState &
  211. MPI_SCSI_STATE_AUTOSENSE_VALID) {
  212. sz = req->u.scsireq.SenseBufferLength;
  213. req_index =
  214. le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
  215. sense_data = ((u8 *)ioc->sense_buf_pool +
  216. (req_index * MPT_SENSE_BUFFER_ALLOC));
  217. memcpy(ioc->ioctl_cmds.sense, sense_data, sz);
  218. ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_SENSE_VALID;
  219. }
  220. }
  221. out:
  222. /* We are done, issue wake up
  223. */
  224. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) {
  225. if (req->u.hdr.Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
  226. mpt_clear_taskmgmt_in_progress_flag(ioc);
  227. ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  228. complete(&ioc->ioctl_cmds.done);
  229. if (ioc->bus_type == SAS)
  230. ioc->schedule_target_reset(ioc);
  231. } else {
  232. ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  233. complete(&ioc->ioctl_cmds.done);
  234. }
  235. }
  236. out_continuation:
  237. if (reply && (reply->u.reply.MsgFlags &
  238. MPI_MSGFLAGS_CONTINUATION_REPLY))
  239. return 0;
  240. return 1;
  241. }
  242. static int
  243. mptctl_taskmgmt_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  244. {
  245. if (!mf)
  246. return 0;
  247. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  248. "TaskMgmt completed (mf=%p, mr=%p)\n",
  249. ioc->name, mf, mr));
  250. ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  251. if (!mr)
  252. goto out;
  253. ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
  254. memcpy(ioc->taskmgmt_cmds.reply, mr,
  255. min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
  256. out:
  257. if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
  258. mpt_clear_taskmgmt_in_progress_flag(ioc);
  259. ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  260. complete(&ioc->taskmgmt_cmds.done);
  261. if (ioc->bus_type == SAS)
  262. ioc->schedule_target_reset(ioc);
  263. return 1;
  264. }
  265. return 0;
  266. }
  267. static int
  268. mptctl_do_taskmgmt(MPT_ADAPTER *ioc, u8 tm_type, u8 bus_id, u8 target_id)
  269. {
  270. MPT_FRAME_HDR *mf;
  271. SCSITaskMgmt_t *pScsiTm;
  272. SCSITaskMgmtReply_t *pScsiTmReply;
  273. int ii;
  274. int retval;
  275. unsigned long timeout;
  276. unsigned long time_count;
  277. u16 iocstatus;
  278. mutex_lock(&ioc->taskmgmt_cmds.mutex);
  279. if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
  280. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  281. return -EPERM;
  282. }
  283. retval = 0;
  284. mf = mpt_get_msg_frame(mptctl_taskmgmt_id, ioc);
  285. if (mf == NULL) {
  286. dtmprintk(ioc,
  287. printk(MYIOC_s_WARN_FMT "TaskMgmt, no msg frames!!\n",
  288. ioc->name));
  289. mpt_clear_taskmgmt_in_progress_flag(ioc);
  290. retval = -ENOMEM;
  291. goto tm_done;
  292. }
  293. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
  294. ioc->name, mf));
  295. pScsiTm = (SCSITaskMgmt_t *) mf;
  296. memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
  297. pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
  298. pScsiTm->TaskType = tm_type;
  299. if ((tm_type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) &&
  300. (ioc->bus_type == FC))
  301. pScsiTm->MsgFlags =
  302. MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
  303. pScsiTm->TargetID = target_id;
  304. pScsiTm->Bus = bus_id;
  305. pScsiTm->ChainOffset = 0;
  306. pScsiTm->Reserved = 0;
  307. pScsiTm->Reserved1 = 0;
  308. pScsiTm->TaskMsgContext = 0;
  309. for (ii= 0; ii < 8; ii++)
  310. pScsiTm->LUN[ii] = 0;
  311. for (ii=0; ii < 7; ii++)
  312. pScsiTm->Reserved2[ii] = 0;
  313. switch (ioc->bus_type) {
  314. case FC:
  315. timeout = 40;
  316. break;
  317. case SAS:
  318. timeout = 30;
  319. break;
  320. case SPI:
  321. default:
  322. timeout = 10;
  323. break;
  324. }
  325. dtmprintk(ioc,
  326. printk(MYIOC_s_DEBUG_FMT "TaskMgmt type=%d timeout=%ld\n",
  327. ioc->name, tm_type, timeout));
  328. INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
  329. time_count = jiffies;
  330. if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
  331. (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
  332. mpt_put_msg_frame_hi_pri(mptctl_taskmgmt_id, ioc, mf);
  333. else {
  334. retval = mpt_send_handshake_request(mptctl_taskmgmt_id, ioc,
  335. sizeof(SCSITaskMgmt_t), (u32 *)pScsiTm, CAN_SLEEP);
  336. if (retval != 0) {
  337. dfailprintk(ioc,
  338. printk(MYIOC_s_ERR_FMT
  339. "TaskMgmt send_handshake FAILED!"
  340. " (ioc %p, mf %p, rc=%d) \n", ioc->name,
  341. ioc, mf, retval));
  342. mpt_free_msg_frame(ioc, mf);
  343. mpt_clear_taskmgmt_in_progress_flag(ioc);
  344. goto tm_done;
  345. }
  346. }
  347. /* Now wait for the command to complete */
  348. ii = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ);
  349. if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  350. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  351. "TaskMgmt failed\n", ioc->name));
  352. mpt_free_msg_frame(ioc, mf);
  353. mpt_clear_taskmgmt_in_progress_flag(ioc);
  354. if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
  355. retval = 0;
  356. else
  357. retval = -1; /* return failure */
  358. goto tm_done;
  359. }
  360. if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
  361. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  362. "TaskMgmt failed\n", ioc->name));
  363. retval = -1; /* return failure */
  364. goto tm_done;
  365. }
  366. pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply;
  367. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  368. "TaskMgmt fw_channel = %d, fw_id = %d, task_type=0x%02X, "
  369. "iocstatus=0x%04X\n\tloginfo=0x%08X, response_code=0x%02X, "
  370. "term_cmnds=%d\n", ioc->name, pScsiTmReply->Bus,
  371. pScsiTmReply->TargetID, tm_type,
  372. le16_to_cpu(pScsiTmReply->IOCStatus),
  373. le32_to_cpu(pScsiTmReply->IOCLogInfo),
  374. pScsiTmReply->ResponseCode,
  375. le32_to_cpu(pScsiTmReply->TerminationCount)));
  376. iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  377. if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
  378. iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED ||
  379. iocstatus == MPI_IOCSTATUS_SUCCESS)
  380. retval = 0;
  381. else {
  382. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  383. "TaskMgmt failed\n", ioc->name));
  384. retval = -1; /* return failure */
  385. }
  386. tm_done:
  387. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  388. CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
  389. return retval;
  390. }
  391. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  392. /* mptctl_timeout_expired
  393. *
  394. * Expecting an interrupt, however timed out.
  395. *
  396. */
  397. static void
  398. mptctl_timeout_expired(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  399. {
  400. unsigned long flags;
  401. int ret_val = -1;
  402. SCSIIORequest_t *scsi_req = (SCSIIORequest_t *) mf;
  403. u8 function = mf->u.hdr.Function;
  404. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": %s\n",
  405. ioc->name, __func__));
  406. if (mpt_fwfault_debug)
  407. mpt_halt_firmware(ioc);
  408. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  409. if (ioc->ioc_reset_in_progress) {
  410. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  411. CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status)
  412. mpt_free_msg_frame(ioc, mf);
  413. return;
  414. }
  415. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  416. CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status)
  417. if (ioc->bus_type == SAS) {
  418. if (function == MPI_FUNCTION_SCSI_IO_REQUEST)
  419. ret_val = mptctl_do_taskmgmt(ioc,
  420. MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
  421. scsi_req->Bus, scsi_req->TargetID);
  422. else if (function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)
  423. ret_val = mptctl_do_taskmgmt(ioc,
  424. MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
  425. scsi_req->Bus, 0);
  426. if (!ret_val)
  427. return;
  428. } else {
  429. if ((function == MPI_FUNCTION_SCSI_IO_REQUEST) ||
  430. (function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH))
  431. ret_val = mptctl_do_taskmgmt(ioc,
  432. MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
  433. scsi_req->Bus, 0);
  434. if (!ret_val)
  435. return;
  436. }
  437. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling Reset! \n",
  438. ioc->name));
  439. mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
  440. mpt_free_msg_frame(ioc, mf);
  441. }
  442. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  443. /* mptctl_ioc_reset
  444. *
  445. * Clean-up functionality. Used only if there has been a
  446. * reload of the FW due.
  447. *
  448. */
  449. static int
  450. mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  451. {
  452. switch(reset_phase) {
  453. case MPT_IOC_SETUP_RESET:
  454. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  455. "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
  456. break;
  457. case MPT_IOC_PRE_RESET:
  458. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  459. "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
  460. break;
  461. case MPT_IOC_POST_RESET:
  462. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  463. "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
  464. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) {
  465. ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
  466. complete(&ioc->ioctl_cmds.done);
  467. }
  468. break;
  469. default:
  470. break;
  471. }
  472. return 1;
  473. }
  474. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  475. /* ASYNC Event Notification Support */
  476. static int
  477. mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
  478. {
  479. u8 event;
  480. event = le32_to_cpu(pEvReply->Event) & 0xFF;
  481. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s() called\n",
  482. ioc->name, __func__));
  483. if(async_queue == NULL)
  484. return 1;
  485. /* Raise SIGIO for persistent events.
  486. * TODO - this define is not in MPI spec yet,
  487. * but they plan to set it to 0x21
  488. */
  489. if (event == 0x21 ) {
  490. ioc->aen_event_read_flag=1;
  491. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Raised SIGIO to application\n",
  492. ioc->name));
  493. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  494. "Raised SIGIO to application\n", ioc->name));
  495. kill_fasync(&async_queue, SIGIO, POLL_IN);
  496. return 1;
  497. }
  498. /* This flag is set after SIGIO was raised, and
  499. * remains set until the application has read
  500. * the event log via ioctl=MPTEVENTREPORT
  501. */
  502. if(ioc->aen_event_read_flag)
  503. return 1;
  504. /* Signal only for the events that are
  505. * requested for by the application
  506. */
  507. if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
  508. ioc->aen_event_read_flag=1;
  509. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  510. "Raised SIGIO to application\n", ioc->name));
  511. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  512. "Raised SIGIO to application\n", ioc->name));
  513. kill_fasync(&async_queue, SIGIO, POLL_IN);
  514. }
  515. return 1;
  516. }
  517. static int
  518. mptctl_fasync(int fd, struct file *filep, int mode)
  519. {
  520. MPT_ADAPTER *ioc;
  521. int ret;
  522. mutex_lock(&mpctl_mutex);
  523. list_for_each_entry(ioc, &ioc_list, list)
  524. ioc->aen_event_read_flag=0;
  525. ret = fasync_helper(fd, filep, mode, &async_queue);
  526. mutex_unlock(&mpctl_mutex);
  527. return ret;
  528. }
  529. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  530. /*
  531. * MPT ioctl handler
  532. * cmd - specify the particular IOCTL command to be issued
  533. * arg - data specific to the command. Must not be null.
  534. */
  535. static long
  536. __mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  537. {
  538. mpt_ioctl_header __user *uhdr = (void __user *) arg;
  539. mpt_ioctl_header khdr;
  540. int iocnum;
  541. unsigned iocnumX;
  542. int nonblock = (file->f_flags & O_NONBLOCK);
  543. int ret;
  544. MPT_ADAPTER *iocp = NULL;
  545. if (copy_from_user(&khdr, uhdr, sizeof(khdr))) {
  546. printk(KERN_ERR MYNAM "%s::mptctl_ioctl() @%d - "
  547. "Unable to copy mpt_ioctl_header data @ %p\n",
  548. __FILE__, __LINE__, uhdr);
  549. return -EFAULT;
  550. }
  551. ret = -ENXIO; /* (-6) No such device or address */
  552. /* Verify intended MPT adapter - set iocnum and the adapter
  553. * pointer (iocp)
  554. */
  555. iocnumX = khdr.iocnum & 0xFF;
  556. if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
  557. (iocp == NULL))
  558. return -ENODEV;
  559. if (!iocp->active) {
  560. printk(KERN_DEBUG MYNAM "%s::mptctl_ioctl() @%d - Controller disabled.\n",
  561. __FILE__, __LINE__);
  562. return -EFAULT;
  563. }
  564. /* Handle those commands that are just returning
  565. * information stored in the driver.
  566. * These commands should never time out and are unaffected
  567. * by TM and FW reloads.
  568. */
  569. if ((cmd & ~IOCSIZE_MASK) == (MPTIOCINFO & ~IOCSIZE_MASK)) {
  570. return mptctl_getiocinfo(arg, _IOC_SIZE(cmd));
  571. } else if (cmd == MPTTARGETINFO) {
  572. return mptctl_gettargetinfo(arg);
  573. } else if (cmd == MPTTEST) {
  574. return mptctl_readtest(arg);
  575. } else if (cmd == MPTEVENTQUERY) {
  576. return mptctl_eventquery(arg);
  577. } else if (cmd == MPTEVENTENABLE) {
  578. return mptctl_eventenable(arg);
  579. } else if (cmd == MPTEVENTREPORT) {
  580. return mptctl_eventreport(arg);
  581. } else if (cmd == MPTFWREPLACE) {
  582. return mptctl_replace_fw(arg);
  583. }
  584. /* All of these commands require an interrupt or
  585. * are unknown/illegal.
  586. */
  587. if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
  588. return ret;
  589. if (cmd == MPTFWDOWNLOAD)
  590. ret = mptctl_fw_download(arg);
  591. else if (cmd == MPTCOMMAND)
  592. ret = mptctl_mpt_command(arg);
  593. else if (cmd == MPTHARDRESET)
  594. ret = mptctl_do_reset(arg);
  595. else if ((cmd & ~IOCSIZE_MASK) == (HP_GETHOSTINFO & ~IOCSIZE_MASK))
  596. ret = mptctl_hp_hostinfo(arg, _IOC_SIZE(cmd));
  597. else if (cmd == HP_GETTARGETINFO)
  598. ret = mptctl_hp_targetinfo(arg);
  599. else
  600. ret = -EINVAL;
  601. mutex_unlock(&iocp->ioctl_cmds.mutex);
  602. return ret;
  603. }
  604. static long
  605. mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  606. {
  607. long ret;
  608. mutex_lock(&mpctl_mutex);
  609. ret = __mptctl_ioctl(file, cmd, arg);
  610. mutex_unlock(&mpctl_mutex);
  611. return ret;
  612. }
  613. static int mptctl_do_reset(unsigned long arg)
  614. {
  615. struct mpt_ioctl_diag_reset __user *urinfo = (void __user *) arg;
  616. struct mpt_ioctl_diag_reset krinfo;
  617. MPT_ADAPTER *iocp;
  618. if (copy_from_user(&krinfo, urinfo, sizeof(struct mpt_ioctl_diag_reset))) {
  619. printk(KERN_ERR MYNAM "%s@%d::mptctl_do_reset - "
  620. "Unable to copy mpt_ioctl_diag_reset struct @ %p\n",
  621. __FILE__, __LINE__, urinfo);
  622. return -EFAULT;
  623. }
  624. if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) {
  625. printk(KERN_DEBUG MYNAM "%s@%d::mptctl_do_reset - ioc%d not found!\n",
  626. __FILE__, __LINE__, krinfo.hdr.iocnum);
  627. return -ENODEV; /* (-6) No such device or address */
  628. }
  629. dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "mptctl_do_reset called.\n",
  630. iocp->name));
  631. if (mpt_HardResetHandler(iocp, CAN_SLEEP) != 0) {
  632. printk (MYIOC_s_ERR_FMT "%s@%d::mptctl_do_reset - reset failed.\n",
  633. iocp->name, __FILE__, __LINE__);
  634. return -1;
  635. }
  636. return 0;
  637. }
  638. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  639. /*
  640. * MPT FW download function. Cast the arg into the mpt_fw_xfer structure.
  641. * This structure contains: iocnum, firmware length (bytes),
  642. * pointer to user space memory where the fw image is stored.
  643. *
  644. * Outputs: None.
  645. * Return: 0 if successful
  646. * -EFAULT if data unavailable
  647. * -ENXIO if no such device
  648. * -EAGAIN if resource problem
  649. * -ENOMEM if no memory for SGE
  650. * -EMLINK if too many chain buffers required
  651. * -EBADRQC if adapter does not support FW download
  652. * -EBUSY if adapter is busy
  653. * -ENOMSG if FW upload returned bad status
  654. */
  655. static int
  656. mptctl_fw_download(unsigned long arg)
  657. {
  658. struct mpt_fw_xfer __user *ufwdl = (void __user *) arg;
  659. struct mpt_fw_xfer kfwdl;
  660. if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) {
  661. printk(KERN_ERR MYNAM "%s@%d::_ioctl_fwdl - "
  662. "Unable to copy mpt_fw_xfer struct @ %p\n",
  663. __FILE__, __LINE__, ufwdl);
  664. return -EFAULT;
  665. }
  666. return mptctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen);
  667. }
  668. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  669. /*
  670. * FW Download engine.
  671. * Outputs: None.
  672. * Return: 0 if successful
  673. * -EFAULT if data unavailable
  674. * -ENXIO if no such device
  675. * -EAGAIN if resource problem
  676. * -ENOMEM if no memory for SGE
  677. * -EMLINK if too many chain buffers required
  678. * -EBADRQC if adapter does not support FW download
  679. * -EBUSY if adapter is busy
  680. * -ENOMSG if FW upload returned bad status
  681. */
  682. static int
  683. mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen)
  684. {
  685. FWDownload_t *dlmsg;
  686. MPT_FRAME_HDR *mf;
  687. MPT_ADAPTER *iocp;
  688. FWDownloadTCSGE_t *ptsge;
  689. MptSge_t *sgl, *sgIn;
  690. char *sgOut;
  691. struct buflist *buflist;
  692. struct buflist *bl;
  693. dma_addr_t sgl_dma;
  694. int ret;
  695. int numfrags = 0;
  696. int maxfrags;
  697. int n = 0;
  698. u32 sgdir;
  699. u32 nib;
  700. int fw_bytes_copied = 0;
  701. int i;
  702. int sge_offset = 0;
  703. u16 iocstat;
  704. pFWDownloadReply_t ReplyMsg = NULL;
  705. unsigned long timeleft;
  706. if (mpt_verify_adapter(ioc, &iocp) < 0) {
  707. printk(KERN_DEBUG MYNAM "ioctl_fwdl - ioc%d not found!\n",
  708. ioc);
  709. return -ENODEV; /* (-6) No such device or address */
  710. } else {
  711. /* Valid device. Get a message frame and construct the FW download message.
  712. */
  713. if ((mf = mpt_get_msg_frame(mptctl_id, iocp)) == NULL)
  714. return -EAGAIN;
  715. }
  716. dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT
  717. "mptctl_do_fwdl called. mptctl_id = %xh.\n", iocp->name, mptctl_id));
  718. dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.bufp = %p\n",
  719. iocp->name, ufwbuf));
  720. dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.fwlen = %d\n",
  721. iocp->name, (int)fwlen));
  722. dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.ioc = %04xh\n",
  723. iocp->name, ioc));
  724. dlmsg = (FWDownload_t*) mf;
  725. ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL;
  726. sgOut = (char *) (ptsge + 1);
  727. /*
  728. * Construct f/w download request
  729. */
  730. dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW;
  731. dlmsg->Reserved = 0;
  732. dlmsg->ChainOffset = 0;
  733. dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD;
  734. dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0;
  735. if (iocp->facts.MsgVersion >= MPI_VERSION_01_05)
  736. dlmsg->MsgFlags = MPI_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT;
  737. else
  738. dlmsg->MsgFlags = 0;
  739. /* Set up the Transaction SGE.
  740. */
  741. ptsge->Reserved = 0;
  742. ptsge->ContextSize = 0;
  743. ptsge->DetailsLength = 12;
  744. ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
  745. ptsge->Reserved_0100_Checksum = 0;
  746. ptsge->ImageOffset = 0;
  747. ptsge->ImageSize = cpu_to_le32(fwlen);
  748. /* Add the SGL
  749. */
  750. /*
  751. * Need to kmalloc area(s) for holding firmware image bytes.
  752. * But we need to do it piece meal, using a proper
  753. * scatter gather list (with 128kB MAX hunks).
  754. *
  755. * A practical limit here might be # of sg hunks that fit into
  756. * a single IOC request frame; 12 or 8 (see below), so:
  757. * For FC9xx: 12 x 128kB == 1.5 mB (max)
  758. * For C1030: 8 x 128kB == 1 mB (max)
  759. * We could support chaining, but things get ugly(ier:)
  760. *
  761. * Set the sge_offset to the start of the sgl (bytes).
  762. */
  763. sgdir = 0x04000000; /* IOC will READ from sys mem */
  764. sge_offset = sizeof(MPIHeader_t) + sizeof(FWDownloadTCSGE_t);
  765. if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset,
  766. &numfrags, &buflist, &sgl_dma, iocp)) == NULL)
  767. return -ENOMEM;
  768. /*
  769. * We should only need SGL with 2 simple_32bit entries (up to 256 kB)
  770. * for FC9xx f/w image, but calculate max number of sge hunks
  771. * we can fit into a request frame, and limit ourselves to that.
  772. * (currently no chain support)
  773. * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE
  774. * Request maxfrags
  775. * 128 12
  776. * 96 8
  777. * 64 4
  778. */
  779. maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) -
  780. sizeof(FWDownloadTCSGE_t))
  781. / iocp->SGE_size;
  782. if (numfrags > maxfrags) {
  783. ret = -EMLINK;
  784. goto fwdl_out;
  785. }
  786. dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: sgl buffer = %p, sgfrags = %d\n",
  787. iocp->name, sgl, numfrags));
  788. /*
  789. * Parse SG list, copying sgl itself,
  790. * plus f/w image hunks from user space as we go...
  791. */
  792. ret = -EFAULT;
  793. sgIn = sgl;
  794. bl = buflist;
  795. for (i=0; i < numfrags; i++) {
  796. /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE
  797. * Skip everything but Simple. If simple, copy from
  798. * user space into kernel space.
  799. * Note: we should not have anything but Simple as
  800. * Chain SGE are illegal.
  801. */
  802. nib = (sgIn->FlagsLength & 0x30000000) >> 28;
  803. if (nib == 0 || nib == 3) {
  804. ;
  805. } else if (sgIn->Address) {
  806. iocp->add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
  807. n++;
  808. if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) {
  809. printk(MYIOC_s_ERR_FMT "%s@%d::_ioctl_fwdl - "
  810. "Unable to copy f/w buffer hunk#%d @ %p\n",
  811. iocp->name, __FILE__, __LINE__, n, ufwbuf);
  812. goto fwdl_out;
  813. }
  814. fw_bytes_copied += bl->len;
  815. }
  816. sgIn++;
  817. bl++;
  818. sgOut += iocp->SGE_size;
  819. }
  820. DBG_DUMP_FW_DOWNLOAD(iocp, (u32 *)mf, numfrags);
  821. /*
  822. * Finally, perform firmware download.
  823. */
  824. ReplyMsg = NULL;
  825. SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, dlmsg->MsgContext);
  826. INITIALIZE_MGMT_STATUS(iocp->ioctl_cmds.status)
  827. mpt_put_msg_frame(mptctl_id, iocp, mf);
  828. /* Now wait for the command to complete */
  829. retry_wait:
  830. timeleft = wait_for_completion_timeout(&iocp->ioctl_cmds.done, HZ*60);
  831. if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  832. ret = -ETIME;
  833. printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__);
  834. if (iocp->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
  835. mpt_free_msg_frame(iocp, mf);
  836. goto fwdl_out;
  837. }
  838. if (!timeleft) {
  839. printk(MYIOC_s_WARN_FMT
  840. "FW download timeout, doorbell=0x%08x\n",
  841. iocp->name, mpt_GetIocState(iocp, 0));
  842. mptctl_timeout_expired(iocp, mf);
  843. } else
  844. goto retry_wait;
  845. goto fwdl_out;
  846. }
  847. if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
  848. printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__);
  849. mpt_free_msg_frame(iocp, mf);
  850. ret = -ENODATA;
  851. goto fwdl_out;
  852. }
  853. if (sgl)
  854. kfree_sgl(sgl, sgl_dma, buflist, iocp);
  855. ReplyMsg = (pFWDownloadReply_t)iocp->ioctl_cmds.reply;
  856. iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK;
  857. if (iocstat == MPI_IOCSTATUS_SUCCESS) {
  858. printk(MYIOC_s_INFO_FMT "F/W update successful!\n", iocp->name);
  859. return 0;
  860. } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) {
  861. printk(MYIOC_s_WARN_FMT "Hmmm... F/W download not supported!?!\n",
  862. iocp->name);
  863. printk(MYIOC_s_WARN_FMT "(time to go bang on somebodies door)\n",
  864. iocp->name);
  865. return -EBADRQC;
  866. } else if (iocstat == MPI_IOCSTATUS_BUSY) {
  867. printk(MYIOC_s_WARN_FMT "IOC_BUSY!\n", iocp->name);
  868. printk(MYIOC_s_WARN_FMT "(try again later?)\n", iocp->name);
  869. return -EBUSY;
  870. } else {
  871. printk(MYIOC_s_WARN_FMT "ioctl_fwdl() returned [bad] status = %04xh\n",
  872. iocp->name, iocstat);
  873. printk(MYIOC_s_WARN_FMT "(bad VooDoo)\n", iocp->name);
  874. return -ENOMSG;
  875. }
  876. return 0;
  877. fwdl_out:
  878. CLEAR_MGMT_STATUS(iocp->ioctl_cmds.status);
  879. SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, 0);
  880. kfree_sgl(sgl, sgl_dma, buflist, iocp);
  881. return ret;
  882. }
  883. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  884. /*
  885. * SGE Allocation routine
  886. *
  887. * Inputs: bytes - number of bytes to be transferred
  888. * sgdir - data direction
  889. * sge_offset - offset (in bytes) from the start of the request
  890. * frame to the first SGE
  891. * ioc - pointer to the mptadapter
  892. * Outputs: frags - number of scatter gather elements
  893. * blp - point to the buflist pointer
  894. * sglbuf_dma - pointer to the (dma) sgl
  895. * Returns: Null if failes
  896. * pointer to the (virtual) sgl if successful.
  897. */
  898. static MptSge_t *
  899. kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
  900. struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc)
  901. {
  902. MptSge_t *sglbuf = NULL; /* pointer to array of SGE */
  903. /* and chain buffers */
  904. struct buflist *buflist = NULL; /* kernel routine */
  905. MptSge_t *sgl;
  906. int numfrags = 0;
  907. int fragcnt = 0;
  908. int alloc_sz = min(bytes,MAX_KMALLOC_SZ); // avoid kernel warning msg!
  909. int bytes_allocd = 0;
  910. int this_alloc;
  911. dma_addr_t pa; // phys addr
  912. int i, buflist_ent;
  913. int sg_spill = MAX_FRAGS_SPILL1;
  914. int dir;
  915. if (bytes < 0)
  916. return NULL;
  917. /* initialization */
  918. *frags = 0;
  919. *blp = NULL;
  920. /* Allocate and initialize an array of kernel
  921. * structures for the SG elements.
  922. */
  923. i = MAX_SGL_BYTES / 8;
  924. buflist = kzalloc(i, GFP_USER);
  925. if (!buflist)
  926. return NULL;
  927. buflist_ent = 0;
  928. /* Allocate a single block of memory to store the sg elements and
  929. * the chain buffers. The calling routine is responsible for
  930. * copying the data in this array into the correct place in the
  931. * request and chain buffers.
  932. */
  933. sglbuf = pci_alloc_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf_dma);
  934. if (sglbuf == NULL)
  935. goto free_and_fail;
  936. if (sgdir & 0x04000000)
  937. dir = PCI_DMA_TODEVICE;
  938. else
  939. dir = PCI_DMA_FROMDEVICE;
  940. /* At start:
  941. * sgl = sglbuf = point to beginning of sg buffer
  942. * buflist_ent = 0 = first kernel structure
  943. * sg_spill = number of SGE that can be written before the first
  944. * chain element.
  945. *
  946. */
  947. sgl = sglbuf;
  948. sg_spill = ((ioc->req_sz - sge_offset)/ioc->SGE_size) - 1;
  949. while (bytes_allocd < bytes) {
  950. this_alloc = min(alloc_sz, bytes-bytes_allocd);
  951. buflist[buflist_ent].len = this_alloc;
  952. buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev,
  953. this_alloc,
  954. &pa);
  955. if (buflist[buflist_ent].kptr == NULL) {
  956. alloc_sz = alloc_sz / 2;
  957. if (alloc_sz == 0) {
  958. printk(MYIOC_s_WARN_FMT "-SG: No can do - "
  959. "not enough memory! :-(\n", ioc->name);
  960. printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n",
  961. ioc->name, numfrags);
  962. goto free_and_fail;
  963. }
  964. continue;
  965. } else {
  966. dma_addr_t dma_addr;
  967. bytes_allocd += this_alloc;
  968. sgl->FlagsLength = (0x10000000|sgdir|this_alloc);
  969. dma_addr = pci_map_single(ioc->pcidev,
  970. buflist[buflist_ent].kptr, this_alloc, dir);
  971. sgl->Address = dma_addr;
  972. fragcnt++;
  973. numfrags++;
  974. sgl++;
  975. buflist_ent++;
  976. }
  977. if (bytes_allocd >= bytes)
  978. break;
  979. /* Need to chain? */
  980. if (fragcnt == sg_spill) {
  981. printk(MYIOC_s_WARN_FMT
  982. "-SG: No can do - " "Chain required! :-(\n", ioc->name);
  983. printk(MYIOC_s_WARN_FMT "(freeing %d frags)\n", ioc->name, numfrags);
  984. goto free_and_fail;
  985. }
  986. /* overflow check... */
  987. if (numfrags*8 > MAX_SGL_BYTES){
  988. /* GRRRRR... */
  989. printk(MYIOC_s_WARN_FMT "-SG: No can do - "
  990. "too many SG frags! :-(\n", ioc->name);
  991. printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n",
  992. ioc->name, numfrags);
  993. goto free_and_fail;
  994. }
  995. }
  996. /* Last sge fixup: set LE+eol+eob bits */
  997. sgl[-1].FlagsLength |= 0xC1000000;
  998. *frags = numfrags;
  999. *blp = buflist;
  1000. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - "
  1001. "%d SG frags generated!\n", ioc->name, numfrags));
  1002. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - "
  1003. "last (big) alloc_sz=%d\n", ioc->name, alloc_sz));
  1004. return sglbuf;
  1005. free_and_fail:
  1006. if (sglbuf != NULL) {
  1007. for (i = 0; i < numfrags; i++) {
  1008. dma_addr_t dma_addr;
  1009. u8 *kptr;
  1010. int len;
  1011. if ((sglbuf[i].FlagsLength >> 24) == 0x30)
  1012. continue;
  1013. dma_addr = sglbuf[i].Address;
  1014. kptr = buflist[i].kptr;
  1015. len = buflist[i].len;
  1016. pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
  1017. }
  1018. pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf, *sglbuf_dma);
  1019. }
  1020. kfree(buflist);
  1021. return NULL;
  1022. }
  1023. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1024. /*
  1025. * Routine to free the SGL elements.
  1026. */
  1027. static void
  1028. kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, struct buflist *buflist, MPT_ADAPTER *ioc)
  1029. {
  1030. MptSge_t *sg = sgl;
  1031. struct buflist *bl = buflist;
  1032. u32 nib;
  1033. int dir;
  1034. int n = 0;
  1035. if (sg->FlagsLength & 0x04000000)
  1036. dir = PCI_DMA_TODEVICE;
  1037. else
  1038. dir = PCI_DMA_FROMDEVICE;
  1039. nib = (sg->FlagsLength & 0xF0000000) >> 28;
  1040. while (! (nib & 0x4)) { /* eob */
  1041. /* skip ignore/chain. */
  1042. if (nib == 0 || nib == 3) {
  1043. ;
  1044. } else if (sg->Address) {
  1045. dma_addr_t dma_addr;
  1046. void *kptr;
  1047. int len;
  1048. dma_addr = sg->Address;
  1049. kptr = bl->kptr;
  1050. len = bl->len;
  1051. pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
  1052. pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
  1053. n++;
  1054. }
  1055. sg++;
  1056. bl++;
  1057. nib = (le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28;
  1058. }
  1059. /* we're at eob! */
  1060. if (sg->Address) {
  1061. dma_addr_t dma_addr;
  1062. void *kptr;
  1063. int len;
  1064. dma_addr = sg->Address;
  1065. kptr = bl->kptr;
  1066. len = bl->len;
  1067. pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
  1068. pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
  1069. n++;
  1070. }
  1071. pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sgl, sgl_dma);
  1072. kfree(buflist);
  1073. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: Free'd 1 SGL buf + %d kbufs!\n",
  1074. ioc->name, n));
  1075. }
  1076. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1077. /*
  1078. * mptctl_getiocinfo - Query the host adapter for IOC information.
  1079. * @arg: User space argument
  1080. *
  1081. * Outputs: None.
  1082. * Return: 0 if successful
  1083. * -EFAULT if data unavailable
  1084. * -ENODEV if no such device/adapter
  1085. */
  1086. static int
  1087. mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
  1088. {
  1089. struct mpt_ioctl_iocinfo __user *uarg = (void __user *) arg;
  1090. struct mpt_ioctl_iocinfo *karg;
  1091. MPT_ADAPTER *ioc;
  1092. struct pci_dev *pdev;
  1093. int iocnum;
  1094. unsigned int port;
  1095. int cim_rev;
  1096. struct scsi_device *sdev;
  1097. VirtDevice *vdevice;
  1098. /* Add of PCI INFO results in unaligned access for
  1099. * IA64 and Sparc. Reset long to int. Return no PCI
  1100. * data for obsolete format.
  1101. */
  1102. if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev0))
  1103. cim_rev = 0;
  1104. else if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev1))
  1105. cim_rev = 1;
  1106. else if (data_size == sizeof(struct mpt_ioctl_iocinfo))
  1107. cim_rev = 2;
  1108. else if (data_size == (sizeof(struct mpt_ioctl_iocinfo_rev0)+12))
  1109. cim_rev = 0; /* obsolete */
  1110. else
  1111. return -EFAULT;
  1112. karg = memdup_user(uarg, data_size);
  1113. if (IS_ERR(karg)) {
  1114. printk(KERN_ERR MYNAM "%s@%d::mpt_ioctl_iocinfo() - memdup_user returned error [%ld]\n",
  1115. __FILE__, __LINE__, PTR_ERR(karg));
  1116. return PTR_ERR(karg);
  1117. }
  1118. if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
  1119. (ioc == NULL)) {
  1120. printk(KERN_DEBUG MYNAM "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
  1121. __FILE__, __LINE__, iocnum);
  1122. kfree(karg);
  1123. return -ENODEV;
  1124. }
  1125. /* Verify the data transfer size is correct. */
  1126. if (karg->hdr.maxDataSize != data_size) {
  1127. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
  1128. "Structure size mismatch. Command not completed.\n",
  1129. ioc->name, __FILE__, __LINE__);
  1130. kfree(karg);
  1131. return -EFAULT;
  1132. }
  1133. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_getiocinfo called.\n",
  1134. ioc->name));
  1135. /* Fill in the data and return the structure to the calling
  1136. * program
  1137. */
  1138. if (ioc->bus_type == SAS)
  1139. karg->adapterType = MPT_IOCTL_INTERFACE_SAS;
  1140. else if (ioc->bus_type == FC)
  1141. karg->adapterType = MPT_IOCTL_INTERFACE_FC;
  1142. else
  1143. karg->adapterType = MPT_IOCTL_INTERFACE_SCSI;
  1144. if (karg->hdr.port > 1) {
  1145. kfree(karg);
  1146. return -EINVAL;
  1147. }
  1148. port = karg->hdr.port;
  1149. karg->port = port;
  1150. pdev = (struct pci_dev *) ioc->pcidev;
  1151. karg->pciId = pdev->device;
  1152. karg->hwRev = pdev->revision;
  1153. karg->subSystemDevice = pdev->subsystem_device;
  1154. karg->subSystemVendor = pdev->subsystem_vendor;
  1155. if (cim_rev == 1) {
  1156. /* Get the PCI bus, device, and function numbers for the IOC
  1157. */
  1158. karg->pciInfo.u.bits.busNumber = pdev->bus->number;
  1159. karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
  1160. karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
  1161. } else if (cim_rev == 2) {
  1162. /* Get the PCI bus, device, function and segment ID numbers
  1163. for the IOC */
  1164. karg->pciInfo.u.bits.busNumber = pdev->bus->number;
  1165. karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
  1166. karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
  1167. karg->pciInfo.segmentID = pci_domain_nr(pdev->bus);
  1168. }
  1169. /* Get number of devices
  1170. */
  1171. karg->numDevices = 0;
  1172. if (ioc->sh) {
  1173. shost_for_each_device(sdev, ioc->sh) {
  1174. vdevice = sdev->hostdata;
  1175. if (vdevice == NULL || vdevice->vtarget == NULL)
  1176. continue;
  1177. if (vdevice->vtarget->tflags &
  1178. MPT_TARGET_FLAGS_RAID_COMPONENT)
  1179. continue;
  1180. karg->numDevices++;
  1181. }
  1182. }
  1183. /* Set the BIOS and FW Version
  1184. */
  1185. karg->FWVersion = ioc->facts.FWVersion.Word;
  1186. karg->BIOSVersion = ioc->biosVersion;
  1187. /* Set the Version Strings.
  1188. */
  1189. strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH);
  1190. karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0';
  1191. karg->busChangeEvent = 0;
  1192. karg->hostId = ioc->pfacts[port].PortSCSIID;
  1193. karg->rsvd[0] = karg->rsvd[1] = 0;
  1194. /* Copy the data from kernel memory to user memory
  1195. */
  1196. if (copy_to_user((char __user *)arg, karg, data_size)) {
  1197. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
  1198. "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
  1199. ioc->name, __FILE__, __LINE__, uarg);
  1200. kfree(karg);
  1201. return -EFAULT;
  1202. }
  1203. kfree(karg);
  1204. return 0;
  1205. }
  1206. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1207. /*
  1208. * mptctl_gettargetinfo - Query the host adapter for target information.
  1209. * @arg: User space argument
  1210. *
  1211. * Outputs: None.
  1212. * Return: 0 if successful
  1213. * -EFAULT if data unavailable
  1214. * -ENODEV if no such device/adapter
  1215. */
  1216. static int
  1217. mptctl_gettargetinfo (unsigned long arg)
  1218. {
  1219. struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg;
  1220. struct mpt_ioctl_targetinfo karg;
  1221. MPT_ADAPTER *ioc;
  1222. VirtDevice *vdevice;
  1223. char *pmem;
  1224. int *pdata;
  1225. int iocnum;
  1226. int numDevices = 0;
  1227. int lun;
  1228. int maxWordsLeft;
  1229. int numBytes;
  1230. u8 port;
  1231. struct scsi_device *sdev;
  1232. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) {
  1233. printk(KERN_ERR MYNAM "%s@%d::mptctl_gettargetinfo - "
  1234. "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
  1235. __FILE__, __LINE__, uarg);
  1236. return -EFAULT;
  1237. }
  1238. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1239. (ioc == NULL)) {
  1240. printk(KERN_DEBUG MYNAM "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
  1241. __FILE__, __LINE__, iocnum);
  1242. return -ENODEV;
  1243. }
  1244. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_gettargetinfo called.\n",
  1245. ioc->name));
  1246. /* Get the port number and set the maximum number of bytes
  1247. * in the returned structure.
  1248. * Ignore the port setting.
  1249. */
  1250. numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
  1251. maxWordsLeft = numBytes/sizeof(int);
  1252. port = karg.hdr.port;
  1253. if (maxWordsLeft <= 0) {
  1254. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
  1255. ioc->name, __FILE__, __LINE__);
  1256. return -ENOMEM;
  1257. }
  1258. /* Fill in the data and return the structure to the calling
  1259. * program
  1260. */
  1261. /* struct mpt_ioctl_targetinfo does not contain sufficient space
  1262. * for the target structures so when the IOCTL is called, there is
  1263. * not sufficient stack space for the structure. Allocate memory,
  1264. * populate the memory, copy back to the user, then free memory.
  1265. * targetInfo format:
  1266. * bits 31-24: reserved
  1267. * 23-16: LUN
  1268. * 15- 8: Bus Number
  1269. * 7- 0: Target ID
  1270. */
  1271. pmem = kzalloc(numBytes, GFP_KERNEL);
  1272. if (!pmem) {
  1273. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
  1274. ioc->name, __FILE__, __LINE__);
  1275. return -ENOMEM;
  1276. }
  1277. pdata = (int *) pmem;
  1278. /* Get number of devices
  1279. */
  1280. if (ioc->sh){
  1281. shost_for_each_device(sdev, ioc->sh) {
  1282. if (!maxWordsLeft)
  1283. continue;
  1284. vdevice = sdev->hostdata;
  1285. if (vdevice == NULL || vdevice->vtarget == NULL)
  1286. continue;
  1287. if (vdevice->vtarget->tflags &
  1288. MPT_TARGET_FLAGS_RAID_COMPONENT)
  1289. continue;
  1290. lun = (vdevice->vtarget->raidVolume) ? 0x80 : vdevice->lun;
  1291. *pdata = (((u8)lun << 16) + (vdevice->vtarget->channel << 8) +
  1292. (vdevice->vtarget->id ));
  1293. pdata++;
  1294. numDevices++;
  1295. --maxWordsLeft;
  1296. }
  1297. }
  1298. karg.numDevices = numDevices;
  1299. /* Copy part of the data from kernel memory to user memory
  1300. */
  1301. if (copy_to_user((char __user *)arg, &karg,
  1302. sizeof(struct mpt_ioctl_targetinfo))) {
  1303. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - "
  1304. "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
  1305. ioc->name, __FILE__, __LINE__, uarg);
  1306. kfree(pmem);
  1307. return -EFAULT;
  1308. }
  1309. /* Copy the remaining data from kernel memory to user memory
  1310. */
  1311. if (copy_to_user(uarg->targetInfo, pmem, numBytes)) {
  1312. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - "
  1313. "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
  1314. ioc->name, __FILE__, __LINE__, pdata);
  1315. kfree(pmem);
  1316. return -EFAULT;
  1317. }
  1318. kfree(pmem);
  1319. return 0;
  1320. }
  1321. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1322. /* MPT IOCTL Test function.
  1323. *
  1324. * Outputs: None.
  1325. * Return: 0 if successful
  1326. * -EFAULT if data unavailable
  1327. * -ENODEV if no such device/adapter
  1328. */
  1329. static int
  1330. mptctl_readtest (unsigned long arg)
  1331. {
  1332. struct mpt_ioctl_test __user *uarg = (void __user *) arg;
  1333. struct mpt_ioctl_test karg;
  1334. MPT_ADAPTER *ioc;
  1335. int iocnum;
  1336. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_test))) {
  1337. printk(KERN_ERR MYNAM "%s@%d::mptctl_readtest - "
  1338. "Unable to read in mpt_ioctl_test struct @ %p\n",
  1339. __FILE__, __LINE__, uarg);
  1340. return -EFAULT;
  1341. }
  1342. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1343. (ioc == NULL)) {
  1344. printk(KERN_DEBUG MYNAM "%s::mptctl_readtest() @%d - ioc%d not found!\n",
  1345. __FILE__, __LINE__, iocnum);
  1346. return -ENODEV;
  1347. }
  1348. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_readtest called.\n",
  1349. ioc->name));
  1350. /* Fill in the data and return the structure to the calling
  1351. * program
  1352. */
  1353. #ifdef MFCNT
  1354. karg.chip_type = ioc->mfcnt;
  1355. #else
  1356. karg.chip_type = ioc->pcidev->device;
  1357. #endif
  1358. strncpy (karg.name, ioc->name, MPT_MAX_NAME);
  1359. karg.name[MPT_MAX_NAME-1]='\0';
  1360. strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH);
  1361. karg.product[MPT_PRODUCT_LENGTH-1]='\0';
  1362. /* Copy the data from kernel memory to user memory
  1363. */
  1364. if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_test))) {
  1365. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_readtest - "
  1366. "Unable to write out mpt_ioctl_test struct @ %p\n",
  1367. ioc->name, __FILE__, __LINE__, uarg);
  1368. return -EFAULT;
  1369. }
  1370. return 0;
  1371. }
  1372. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1373. /*
  1374. * mptctl_eventquery - Query the host adapter for the event types
  1375. * that are being logged.
  1376. * @arg: User space argument
  1377. *
  1378. * Outputs: None.
  1379. * Return: 0 if successful
  1380. * -EFAULT if data unavailable
  1381. * -ENODEV if no such device/adapter
  1382. */
  1383. static int
  1384. mptctl_eventquery (unsigned long arg)
  1385. {
  1386. struct mpt_ioctl_eventquery __user *uarg = (void __user *) arg;
  1387. struct mpt_ioctl_eventquery karg;
  1388. MPT_ADAPTER *ioc;
  1389. int iocnum;
  1390. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventquery))) {
  1391. printk(KERN_ERR MYNAM "%s@%d::mptctl_eventquery - "
  1392. "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
  1393. __FILE__, __LINE__, uarg);
  1394. return -EFAULT;
  1395. }
  1396. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1397. (ioc == NULL)) {
  1398. printk(KERN_DEBUG MYNAM "%s::mptctl_eventquery() @%d - ioc%d not found!\n",
  1399. __FILE__, __LINE__, iocnum);
  1400. return -ENODEV;
  1401. }
  1402. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventquery called.\n",
  1403. ioc->name));
  1404. karg.eventEntries = MPTCTL_EVENT_LOG_SIZE;
  1405. karg.eventTypes = ioc->eventTypes;
  1406. /* Copy the data from kernel memory to user memory
  1407. */
  1408. if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_eventquery))) {
  1409. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventquery - "
  1410. "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
  1411. ioc->name, __FILE__, __LINE__, uarg);
  1412. return -EFAULT;
  1413. }
  1414. return 0;
  1415. }
  1416. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1417. static int
  1418. mptctl_eventenable (unsigned long arg)
  1419. {
  1420. struct mpt_ioctl_eventenable __user *uarg = (void __user *) arg;
  1421. struct mpt_ioctl_eventenable karg;
  1422. MPT_ADAPTER *ioc;
  1423. int iocnum;
  1424. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventenable))) {
  1425. printk(KERN_ERR MYNAM "%s@%d::mptctl_eventenable - "
  1426. "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
  1427. __FILE__, __LINE__, uarg);
  1428. return -EFAULT;
  1429. }
  1430. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1431. (ioc == NULL)) {
  1432. printk(KERN_DEBUG MYNAM "%s::mptctl_eventenable() @%d - ioc%d not found!\n",
  1433. __FILE__, __LINE__, iocnum);
  1434. return -ENODEV;
  1435. }
  1436. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventenable called.\n",
  1437. ioc->name));
  1438. if (ioc->events == NULL) {
  1439. /* Have not yet allocated memory - do so now.
  1440. */
  1441. int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
  1442. ioc->events = kzalloc(sz, GFP_KERNEL);
  1443. if (!ioc->events) {
  1444. printk(MYIOC_s_ERR_FMT
  1445. ": ERROR - Insufficient memory to add adapter!\n",
  1446. ioc->name);
  1447. return -ENOMEM;
  1448. }
  1449. ioc->alloc_total += sz;
  1450. ioc->eventContext = 0;
  1451. }
  1452. /* Update the IOC event logging flag.
  1453. */
  1454. ioc->eventTypes = karg.eventTypes;
  1455. return 0;
  1456. }
  1457. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1458. static int
  1459. mptctl_eventreport (unsigned long arg)
  1460. {
  1461. struct mpt_ioctl_eventreport __user *uarg = (void __user *) arg;
  1462. struct mpt_ioctl_eventreport karg;
  1463. MPT_ADAPTER *ioc;
  1464. int iocnum;
  1465. int numBytes, maxEvents, max;
  1466. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventreport))) {
  1467. printk(KERN_ERR MYNAM "%s@%d::mptctl_eventreport - "
  1468. "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
  1469. __FILE__, __LINE__, uarg);
  1470. return -EFAULT;
  1471. }
  1472. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1473. (ioc == NULL)) {
  1474. printk(KERN_DEBUG MYNAM "%s::mptctl_eventreport() @%d - ioc%d not found!\n",
  1475. __FILE__, __LINE__, iocnum);
  1476. return -ENODEV;
  1477. }
  1478. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventreport called.\n",
  1479. ioc->name));
  1480. numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
  1481. maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS);
  1482. max = MPTCTL_EVENT_LOG_SIZE < maxEvents ? MPTCTL_EVENT_LOG_SIZE : maxEvents;
  1483. /* If fewer than 1 event is requested, there must have
  1484. * been some type of error.
  1485. */
  1486. if ((max < 1) || !ioc->events)
  1487. return -ENODATA;
  1488. /* reset this flag so SIGIO can restart */
  1489. ioc->aen_event_read_flag=0;
  1490. /* Copy the data from kernel memory to user memory
  1491. */
  1492. numBytes = max * sizeof(MPT_IOCTL_EVENTS);
  1493. if (copy_to_user(uarg->eventData, ioc->events, numBytes)) {
  1494. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventreport - "
  1495. "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
  1496. ioc->name, __FILE__, __LINE__, ioc->events);
  1497. return -EFAULT;
  1498. }
  1499. return 0;
  1500. }
  1501. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1502. static int
  1503. mptctl_replace_fw (unsigned long arg)
  1504. {
  1505. struct mpt_ioctl_replace_fw __user *uarg = (void __user *) arg;
  1506. struct mpt_ioctl_replace_fw karg;
  1507. MPT_ADAPTER *ioc;
  1508. int iocnum;
  1509. int newFwSize;
  1510. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) {
  1511. printk(KERN_ERR MYNAM "%s@%d::mptctl_replace_fw - "
  1512. "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
  1513. __FILE__, __LINE__, uarg);
  1514. return -EFAULT;
  1515. }
  1516. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1517. (ioc == NULL)) {
  1518. printk(KERN_DEBUG MYNAM "%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
  1519. __FILE__, __LINE__, iocnum);
  1520. return -ENODEV;
  1521. }
  1522. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_replace_fw called.\n",
  1523. ioc->name));
  1524. /* If caching FW, Free the old FW image
  1525. */
  1526. if (ioc->cached_fw == NULL)
  1527. return 0;
  1528. mpt_free_fw_memory(ioc);
  1529. /* Allocate memory for the new FW image
  1530. */
  1531. newFwSize = ALIGN(karg.newImageSize, 4);
  1532. mpt_alloc_fw_memory(ioc, newFwSize);
  1533. if (ioc->cached_fw == NULL)
  1534. return -ENOMEM;
  1535. /* Copy the data from user memory to kernel space
  1536. */
  1537. if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {
  1538. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_replace_fw - "
  1539. "Unable to read in mpt_ioctl_replace_fw image "
  1540. "@ %p\n", ioc->name, __FILE__, __LINE__, uarg);
  1541. mpt_free_fw_memory(ioc);
  1542. return -EFAULT;
  1543. }
  1544. /* Update IOCFactsReply
  1545. */
  1546. ioc->facts.FWImageSize = newFwSize;
  1547. return 0;
  1548. }
  1549. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1550. /* MPT IOCTL MPTCOMMAND function.
  1551. * Cast the arg into the mpt_ioctl_mpt_command structure.
  1552. *
  1553. * Outputs: None.
  1554. * Return: 0 if successful
  1555. * -EBUSY if previous command timeout and IOC reset is not complete.
  1556. * -EFAULT if data unavailable
  1557. * -ENODEV if no such device/adapter
  1558. * -ETIME if timer expires
  1559. * -ENOMEM if memory allocation error
  1560. */
  1561. static int
  1562. mptctl_mpt_command (unsigned long arg)
  1563. {
  1564. struct mpt_ioctl_command __user *uarg = (void __user *) arg;
  1565. struct mpt_ioctl_command karg;
  1566. MPT_ADAPTER *ioc;
  1567. int iocnum;
  1568. int rc;
  1569. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_command))) {
  1570. printk(KERN_ERR MYNAM "%s@%d::mptctl_mpt_command - "
  1571. "Unable to read in mpt_ioctl_command struct @ %p\n",
  1572. __FILE__, __LINE__, uarg);
  1573. return -EFAULT;
  1574. }
  1575. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1576. (ioc == NULL)) {
  1577. printk(KERN_DEBUG MYNAM "%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
  1578. __FILE__, __LINE__, iocnum);
  1579. return -ENODEV;
  1580. }
  1581. rc = mptctl_do_mpt_command (karg, &uarg->MF);
  1582. return rc;
  1583. }
  1584. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1585. /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands.
  1586. *
  1587. * Outputs: None.
  1588. * Return: 0 if successful
  1589. * -EBUSY if previous command timeout and IOC reset is not complete.
  1590. * -EFAULT if data unavailable
  1591. * -ENODEV if no such device/adapter
  1592. * -ETIME if timer expires
  1593. * -ENOMEM if memory allocation error
  1594. * -EPERM if SCSI I/O and target is untagged
  1595. */
  1596. static int
  1597. mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
  1598. {
  1599. MPT_ADAPTER *ioc;
  1600. MPT_FRAME_HDR *mf = NULL;
  1601. MPIHeader_t *hdr;
  1602. char *psge;
  1603. struct buflist bufIn; /* data In buffer */
  1604. struct buflist bufOut; /* data Out buffer */
  1605. dma_addr_t dma_addr_in;
  1606. dma_addr_t dma_addr_out;
  1607. int sgSize = 0; /* Num SG elements */
  1608. int iocnum, flagsLength;
  1609. int sz, rc = 0;
  1610. int msgContext;
  1611. u16 req_idx;
  1612. ulong timeout;
  1613. unsigned long timeleft;
  1614. struct scsi_device *sdev;
  1615. unsigned long flags;
  1616. u8 function;
  1617. /* bufIn and bufOut are used for user to kernel space transfers
  1618. */
  1619. bufIn.kptr = bufOut.kptr = NULL;
  1620. bufIn.len = bufOut.len = 0;
  1621. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1622. (ioc == NULL)) {
  1623. printk(KERN_DEBUG MYNAM "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
  1624. __FILE__, __LINE__, iocnum);
  1625. return -ENODEV;
  1626. }
  1627. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  1628. if (ioc->ioc_reset_in_progress) {
  1629. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  1630. printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - "
  1631. "Busy with diagnostic reset\n", __FILE__, __LINE__);
  1632. return -EBUSY;
  1633. }
  1634. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  1635. /* Basic sanity checks to prevent underflows or integer overflows */
  1636. if (karg.maxReplyBytes < 0 ||
  1637. karg.dataInSize < 0 ||
  1638. karg.dataOutSize < 0 ||
  1639. karg.dataSgeOffset < 0 ||
  1640. karg.maxSenseBytes < 0 ||
  1641. karg.dataSgeOffset > ioc->req_sz / 4)
  1642. return -EINVAL;
  1643. /* Verify that the final request frame will not be too large.
  1644. */
  1645. sz = karg.dataSgeOffset * 4;
  1646. if (karg.dataInSize > 0)
  1647. sz += ioc->SGE_size;
  1648. if (karg.dataOutSize > 0)
  1649. sz += ioc->SGE_size;
  1650. if (sz > ioc->req_sz) {
  1651. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1652. "Request frame too large (%d) maximum (%d)\n",
  1653. ioc->name, __FILE__, __LINE__, sz, ioc->req_sz);
  1654. return -EFAULT;
  1655. }
  1656. /* Get a free request frame and save the message context.
  1657. */
  1658. if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
  1659. return -EAGAIN;
  1660. hdr = (MPIHeader_t *) mf;
  1661. msgContext = le32_to_cpu(hdr->MsgContext);
  1662. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  1663. /* Copy the request frame
  1664. * Reset the saved message context.
  1665. * Request frame in user space
  1666. */
  1667. if (copy_from_user(mf, mfPtr, karg.dataSgeOffset * 4)) {
  1668. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1669. "Unable to read MF from mpt_ioctl_command struct @ %p\n",
  1670. ioc->name, __FILE__, __LINE__, mfPtr);
  1671. function = -1;
  1672. rc = -EFAULT;
  1673. goto done_free_mem;
  1674. }
  1675. hdr->MsgContext = cpu_to_le32(msgContext);
  1676. function = hdr->Function;
  1677. /* Verify that this request is allowed.
  1678. */
  1679. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sending mpi function (0x%02X), req=%p\n",
  1680. ioc->name, hdr->Function, mf));
  1681. switch (function) {
  1682. case MPI_FUNCTION_IOC_FACTS:
  1683. case MPI_FUNCTION_PORT_FACTS:
  1684. karg.dataOutSize = karg.dataInSize = 0;
  1685. break;
  1686. case MPI_FUNCTION_CONFIG:
  1687. {
  1688. Config_t *config_frame;
  1689. config_frame = (Config_t *)mf;
  1690. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\ttype=0x%02x ext_type=0x%02x "
  1691. "number=0x%02x action=0x%02x\n", ioc->name,
  1692. config_frame->Header.PageType,
  1693. config_frame->ExtPageType,
  1694. config_frame->Header.PageNumber,
  1695. config_frame->Action));
  1696. break;
  1697. }
  1698. case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND:
  1699. case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND:
  1700. case MPI_FUNCTION_FW_UPLOAD:
  1701. case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
  1702. case MPI_FUNCTION_FW_DOWNLOAD:
  1703. case MPI_FUNCTION_FC_PRIMITIVE_SEND:
  1704. case MPI_FUNCTION_TOOLBOX:
  1705. case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
  1706. break;
  1707. case MPI_FUNCTION_SCSI_IO_REQUEST:
  1708. if (ioc->sh) {
  1709. SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
  1710. int qtag = MPI_SCSIIO_CONTROL_UNTAGGED;
  1711. int scsidir = 0;
  1712. int dataSize;
  1713. u32 id;
  1714. id = (ioc->devices_per_bus == 0) ? 256 : ioc->devices_per_bus;
  1715. if (pScsiReq->TargetID > id) {
  1716. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1717. "Target ID out of bounds. \n",
  1718. ioc->name, __FILE__, __LINE__);
  1719. rc = -ENODEV;
  1720. goto done_free_mem;
  1721. }
  1722. if (pScsiReq->Bus >= ioc->number_of_buses) {
  1723. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1724. "Target Bus out of bounds. \n",
  1725. ioc->name, __FILE__, __LINE__);
  1726. rc = -ENODEV;
  1727. goto done_free_mem;
  1728. }
  1729. pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
  1730. pScsiReq->MsgFlags |= mpt_msg_flags(ioc);
  1731. /* verify that app has not requested
  1732. * more sense data than driver
  1733. * can provide, if so, reset this parameter
  1734. * set the sense buffer pointer low address
  1735. * update the control field to specify Q type
  1736. */
  1737. if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
  1738. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  1739. else
  1740. pScsiReq->SenseBufferLength = karg.maxSenseBytes;
  1741. pScsiReq->SenseBufferLowAddr =
  1742. cpu_to_le32(ioc->sense_buf_low_dma
  1743. + (req_idx * MPT_SENSE_BUFFER_ALLOC));
  1744. shost_for_each_device(sdev, ioc->sh) {
  1745. struct scsi_target *starget = scsi_target(sdev);
  1746. VirtTarget *vtarget = starget->hostdata;
  1747. if (vtarget == NULL)
  1748. continue;
  1749. if ((pScsiReq->TargetID == vtarget->id) &&
  1750. (pScsiReq->Bus == vtarget->channel) &&
  1751. (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
  1752. qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
  1753. }
  1754. /* Have the IOCTL driver set the direction based
  1755. * on the dataOutSize (ordering issue with Sparc).
  1756. */
  1757. if (karg.dataOutSize > 0) {
  1758. scsidir = MPI_SCSIIO_CONTROL_WRITE;
  1759. dataSize = karg.dataOutSize;
  1760. } else {
  1761. scsidir = MPI_SCSIIO_CONTROL_READ;
  1762. dataSize = karg.dataInSize;
  1763. }
  1764. pScsiReq->Control = cpu_to_le32(scsidir | qtag);
  1765. pScsiReq->DataLength = cpu_to_le32(dataSize);
  1766. } else {
  1767. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1768. "SCSI driver is not loaded. \n",
  1769. ioc->name, __FILE__, __LINE__);
  1770. rc = -EFAULT;
  1771. goto done_free_mem;
  1772. }
  1773. break;
  1774. case MPI_FUNCTION_SMP_PASSTHROUGH:
  1775. /* Check mf->PassthruFlags to determine if
  1776. * transfer is ImmediateMode or not.
  1777. * Immediate mode returns data in the ReplyFrame.
  1778. * Else, we are sending request and response data
  1779. * in two SGLs at the end of the mf.
  1780. */
  1781. break;
  1782. case MPI_FUNCTION_SATA_PASSTHROUGH:
  1783. if (!ioc->sh) {
  1784. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1785. "SCSI driver is not loaded. \n",
  1786. ioc->name, __FILE__, __LINE__);
  1787. rc = -EFAULT;
  1788. goto done_free_mem;
  1789. }
  1790. break;
  1791. case MPI_FUNCTION_RAID_ACTION:
  1792. /* Just add a SGE
  1793. */
  1794. break;
  1795. case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
  1796. if (ioc->sh) {
  1797. SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
  1798. int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
  1799. int scsidir = MPI_SCSIIO_CONTROL_READ;
  1800. int dataSize;
  1801. pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
  1802. pScsiReq->MsgFlags |= mpt_msg_flags(ioc);
  1803. /* verify that app has not requested
  1804. * more sense data than driver
  1805. * can provide, if so, reset this parameter
  1806. * set the sense buffer pointer low address
  1807. * update the control field to specify Q type
  1808. */
  1809. if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
  1810. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  1811. else
  1812. pScsiReq->SenseBufferLength = karg.maxSenseBytes;
  1813. pScsiReq->SenseBufferLowAddr =
  1814. cpu_to_le32(ioc->sense_buf_low_dma
  1815. + (req_idx * MPT_SENSE_BUFFER_ALLOC));
  1816. /* All commands to physical devices are tagged
  1817. */
  1818. /* Have the IOCTL driver set the direction based
  1819. * on the dataOutSize (ordering issue with Sparc).
  1820. */
  1821. if (karg.dataOutSize > 0) {
  1822. scsidir = MPI_SCSIIO_CONTROL_WRITE;
  1823. dataSize = karg.dataOutSize;
  1824. } else {
  1825. scsidir = MPI_SCSIIO_CONTROL_READ;
  1826. dataSize = karg.dataInSize;
  1827. }
  1828. pScsiReq->Control = cpu_to_le32(scsidir | qtag);
  1829. pScsiReq->DataLength = cpu_to_le32(dataSize);
  1830. } else {
  1831. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1832. "SCSI driver is not loaded. \n",
  1833. ioc->name, __FILE__, __LINE__);
  1834. rc = -EFAULT;
  1835. goto done_free_mem;
  1836. }
  1837. break;
  1838. case MPI_FUNCTION_SCSI_TASK_MGMT:
  1839. {
  1840. SCSITaskMgmt_t *pScsiTm;
  1841. pScsiTm = (SCSITaskMgmt_t *)mf;
  1842. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1843. "\tTaskType=0x%x MsgFlags=0x%x "
  1844. "TaskMsgContext=0x%x id=%d channel=%d\n",
  1845. ioc->name, pScsiTm->TaskType, le32_to_cpu
  1846. (pScsiTm->TaskMsgContext), pScsiTm->MsgFlags,
  1847. pScsiTm->TargetID, pScsiTm->Bus));
  1848. break;
  1849. }
  1850. case MPI_FUNCTION_IOC_INIT:
  1851. {
  1852. IOCInit_t *pInit = (IOCInit_t *) mf;
  1853. u32 high_addr, sense_high;
  1854. /* Verify that all entries in the IOC INIT match
  1855. * existing setup (and in LE format).
  1856. */
  1857. if (sizeof(dma_addr_t) == sizeof(u64)) {
  1858. high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32));
  1859. sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
  1860. } else {
  1861. high_addr = 0;
  1862. sense_high= 0;
  1863. }
  1864. if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) ||
  1865. (pInit->MaxBuses != ioc->facts.MaxBuses) ||
  1866. (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) ||
  1867. (pInit->HostMfaHighAddr != high_addr) ||
  1868. (pInit->SenseBufferHighAddr != sense_high)) {
  1869. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1870. "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
  1871. ioc->name, __FILE__, __LINE__);
  1872. rc = -EFAULT;
  1873. goto done_free_mem;
  1874. }
  1875. }
  1876. break;
  1877. default:
  1878. /*
  1879. * MPI_FUNCTION_PORT_ENABLE
  1880. * MPI_FUNCTION_TARGET_CMD_BUFFER_POST
  1881. * MPI_FUNCTION_TARGET_ASSIST
  1882. * MPI_FUNCTION_TARGET_STATUS_SEND
  1883. * MPI_FUNCTION_TARGET_MODE_ABORT
  1884. * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
  1885. * MPI_FUNCTION_IO_UNIT_RESET
  1886. * MPI_FUNCTION_HANDSHAKE
  1887. * MPI_FUNCTION_REPLY_FRAME_REMOVAL
  1888. * MPI_FUNCTION_EVENT_NOTIFICATION
  1889. * (driver handles event notification)
  1890. * MPI_FUNCTION_EVENT_ACK
  1891. */
  1892. /* What to do with these??? CHECK ME!!!
  1893. MPI_FUNCTION_FC_LINK_SRVC_BUF_POST
  1894. MPI_FUNCTION_FC_LINK_SRVC_RSP
  1895. MPI_FUNCTION_FC_ABORT
  1896. MPI_FUNCTION_LAN_SEND
  1897. MPI_FUNCTION_LAN_RECEIVE
  1898. MPI_FUNCTION_LAN_RESET
  1899. */
  1900. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1901. "Illegal request (function 0x%x) \n",
  1902. ioc->name, __FILE__, __LINE__, hdr->Function);
  1903. rc = -EFAULT;
  1904. goto done_free_mem;
  1905. }
  1906. /* Add the SGL ( at most one data in SGE and one data out SGE )
  1907. * In the case of two SGE's - the data out (write) will always
  1908. * preceede the data in (read) SGE. psgList is used to free the
  1909. * allocated memory.
  1910. */
  1911. psge = (char *) (((int *) mf) + karg.dataSgeOffset);
  1912. flagsLength = 0;
  1913. if (karg.dataOutSize > 0)
  1914. sgSize ++;
  1915. if (karg.dataInSize > 0)
  1916. sgSize ++;
  1917. if (sgSize > 0) {
  1918. /* Set up the dataOut memory allocation */
  1919. if (karg.dataOutSize > 0) {
  1920. if (karg.dataInSize > 0) {
  1921. flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
  1922. MPI_SGE_FLAGS_END_OF_BUFFER |
  1923. MPI_SGE_FLAGS_DIRECTION)
  1924. << MPI_SGE_FLAGS_SHIFT;
  1925. } else {
  1926. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
  1927. }
  1928. flagsLength |= karg.dataOutSize;
  1929. bufOut.len = karg.dataOutSize;
  1930. bufOut.kptr = pci_alloc_consistent(
  1931. ioc->pcidev, bufOut.len, &dma_addr_out);
  1932. if (bufOut.kptr == NULL) {
  1933. rc = -ENOMEM;
  1934. goto done_free_mem;
  1935. } else {
  1936. /* Set up this SGE.
  1937. * Copy to MF and to sglbuf
  1938. */
  1939. ioc->add_sge(psge, flagsLength, dma_addr_out);
  1940. psge += ioc->SGE_size;
  1941. /* Copy user data to kernel space.
  1942. */
  1943. if (copy_from_user(bufOut.kptr,
  1944. karg.dataOutBufPtr,
  1945. bufOut.len)) {
  1946. printk(MYIOC_s_ERR_FMT
  1947. "%s@%d::mptctl_do_mpt_command - Unable "
  1948. "to read user data "
  1949. "struct @ %p\n",
  1950. ioc->name, __FILE__, __LINE__,karg.dataOutBufPtr);
  1951. rc = -EFAULT;
  1952. goto done_free_mem;
  1953. }
  1954. }
  1955. }
  1956. if (karg.dataInSize > 0) {
  1957. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
  1958. flagsLength |= karg.dataInSize;
  1959. bufIn.len = karg.dataInSize;
  1960. bufIn.kptr = pci_alloc_consistent(ioc->pcidev,
  1961. bufIn.len, &dma_addr_in);
  1962. if (bufIn.kptr == NULL) {
  1963. rc = -ENOMEM;
  1964. goto done_free_mem;
  1965. } else {
  1966. /* Set up this SGE
  1967. * Copy to MF and to sglbuf
  1968. */
  1969. ioc->add_sge(psge, flagsLength, dma_addr_in);
  1970. }
  1971. }
  1972. } else {
  1973. /* Add a NULL SGE
  1974. */
  1975. ioc->add_sge(psge, flagsLength, (dma_addr_t) -1);
  1976. }
  1977. SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, hdr->MsgContext);
  1978. INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
  1979. if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
  1980. mutex_lock(&ioc->taskmgmt_cmds.mutex);
  1981. if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
  1982. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  1983. goto done_free_mem;
  1984. }
  1985. DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
  1986. if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
  1987. (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
  1988. mpt_put_msg_frame_hi_pri(mptctl_id, ioc, mf);
  1989. else {
  1990. rc =mpt_send_handshake_request(mptctl_id, ioc,
  1991. sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
  1992. if (rc != 0) {
  1993. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1994. "send_handshake FAILED! (ioc %p, mf %p)\n",
  1995. ioc->name, ioc, mf));
  1996. mpt_clear_taskmgmt_in_progress_flag(ioc);
  1997. rc = -ENODATA;
  1998. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  1999. goto done_free_mem;
  2000. }
  2001. }
  2002. } else
  2003. mpt_put_msg_frame(mptctl_id, ioc, mf);
  2004. /* Now wait for the command to complete */
  2005. timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT;
  2006. retry_wait:
  2007. timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
  2008. HZ*timeout);
  2009. if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  2010. rc = -ETIME;
  2011. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "%s: TIMED OUT!\n",
  2012. ioc->name, __func__));
  2013. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
  2014. if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
  2015. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  2016. goto done_free_mem;
  2017. }
  2018. if (!timeleft) {
  2019. printk(MYIOC_s_WARN_FMT
  2020. "mpt cmd timeout, doorbell=0x%08x"
  2021. " function=0x%x\n",
  2022. ioc->name, mpt_GetIocState(ioc, 0), function);
  2023. if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
  2024. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  2025. mptctl_timeout_expired(ioc, mf);
  2026. mf = NULL;
  2027. } else
  2028. goto retry_wait;
  2029. goto done_free_mem;
  2030. }
  2031. if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
  2032. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  2033. mf = NULL;
  2034. /* If a valid reply frame, copy to the user.
  2035. * Offset 2: reply length in U32's
  2036. */
  2037. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
  2038. if (karg.maxReplyBytes < ioc->reply_sz) {
  2039. sz = min(karg.maxReplyBytes,
  2040. 4*ioc->ioctl_cmds.reply[2]);
  2041. } else {
  2042. sz = min(ioc->reply_sz, 4*ioc->ioctl_cmds.reply[2]);
  2043. }
  2044. if (sz > 0) {
  2045. if (copy_to_user(karg.replyFrameBufPtr,
  2046. ioc->ioctl_cmds.reply, sz)){
  2047. printk(MYIOC_s_ERR_FMT
  2048. "%s@%d::mptctl_do_mpt_command - "
  2049. "Unable to write out reply frame %p\n",
  2050. ioc->name, __FILE__, __LINE__, karg.replyFrameBufPtr);
  2051. rc = -ENODATA;
  2052. goto done_free_mem;
  2053. }
  2054. }
  2055. }
  2056. /* If valid sense data, copy to user.
  2057. */
  2058. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_SENSE_VALID) {
  2059. sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
  2060. if (sz > 0) {
  2061. if (copy_to_user(karg.senseDataPtr,
  2062. ioc->ioctl_cmds.sense, sz)) {
  2063. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  2064. "Unable to write sense data to user %p\n",
  2065. ioc->name, __FILE__, __LINE__,
  2066. karg.senseDataPtr);
  2067. rc = -ENODATA;
  2068. goto done_free_mem;
  2069. }
  2070. }
  2071. }
  2072. /* If the overall status is _GOOD and data in, copy data
  2073. * to user.
  2074. */
  2075. if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD) &&
  2076. (karg.dataInSize > 0) && (bufIn.kptr)) {
  2077. if (copy_to_user(karg.dataInBufPtr,
  2078. bufIn.kptr, karg.dataInSize)) {
  2079. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  2080. "Unable to write data to user %p\n",
  2081. ioc->name, __FILE__, __LINE__,
  2082. karg.dataInBufPtr);
  2083. rc = -ENODATA;
  2084. }
  2085. }
  2086. done_free_mem:
  2087. CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
  2088. SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
  2089. /* Free the allocated memory.
  2090. */
  2091. if (bufOut.kptr != NULL) {
  2092. pci_free_consistent(ioc->pcidev,
  2093. bufOut.len, (void *) bufOut.kptr, dma_addr_out);
  2094. }
  2095. if (bufIn.kptr != NULL) {
  2096. pci_free_consistent(ioc->pcidev,
  2097. bufIn.len, (void *) bufIn.kptr, dma_addr_in);
  2098. }
  2099. /* mf is null if command issued successfully
  2100. * otherwise, failure occurred after mf acquired.
  2101. */
  2102. if (mf)
  2103. mpt_free_msg_frame(ioc, mf);
  2104. return rc;
  2105. }
  2106. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2107. /* Prototype Routine for the HOST INFO command.
  2108. *
  2109. * Outputs: None.
  2110. * Return: 0 if successful
  2111. * -EFAULT if data unavailable
  2112. * -EBUSY if previous command timeout and IOC reset is not complete.
  2113. * -ENODEV if no such device/adapter
  2114. * -ETIME if timer expires
  2115. * -ENOMEM if memory allocation error
  2116. */
  2117. static int
  2118. mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
  2119. {
  2120. hp_host_info_t __user *uarg = (void __user *) arg;
  2121. MPT_ADAPTER *ioc;
  2122. struct pci_dev *pdev;
  2123. char *pbuf=NULL;
  2124. dma_addr_t buf_dma;
  2125. hp_host_info_t karg;
  2126. CONFIGPARMS cfg;
  2127. ConfigPageHeader_t hdr;
  2128. int iocnum;
  2129. int rc, cim_rev;
  2130. ToolboxIstwiReadWriteRequest_t *IstwiRWRequest;
  2131. MPT_FRAME_HDR *mf = NULL;
  2132. unsigned long timeleft;
  2133. int retval;
  2134. u32 msgcontext;
  2135. /* Reset long to int. Should affect IA64 and SPARC only
  2136. */
  2137. if (data_size == sizeof(hp_host_info_t))
  2138. cim_rev = 1;
  2139. else if (data_size == sizeof(hp_host_info_rev0_t))
  2140. cim_rev = 0; /* obsolete */
  2141. else
  2142. return -EFAULT;
  2143. if (copy_from_user(&karg, uarg, sizeof(hp_host_info_t))) {
  2144. printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_host_info - "
  2145. "Unable to read in hp_host_info struct @ %p\n",
  2146. __FILE__, __LINE__, uarg);
  2147. return -EFAULT;
  2148. }
  2149. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  2150. (ioc == NULL)) {
  2151. printk(KERN_DEBUG MYNAM "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
  2152. __FILE__, __LINE__, iocnum);
  2153. return -ENODEV;
  2154. }
  2155. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_hostinfo called.\n",
  2156. ioc->name));
  2157. /* Fill in the data and return the structure to the calling
  2158. * program
  2159. */
  2160. pdev = (struct pci_dev *) ioc->pcidev;
  2161. karg.vendor = pdev->vendor;
  2162. karg.device = pdev->device;
  2163. karg.subsystem_id = pdev->subsystem_device;
  2164. karg.subsystem_vendor = pdev->subsystem_vendor;
  2165. karg.devfn = pdev->devfn;
  2166. karg.bus = pdev->bus->number;
  2167. /* Save the SCSI host no. if
  2168. * SCSI driver loaded
  2169. */
  2170. if (ioc->sh != NULL)
  2171. karg.host_no = ioc->sh->host_no;
  2172. else
  2173. karg.host_no = -1;
  2174. /* Reformat the fw_version into a string
  2175. */
  2176. karg.fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ?
  2177. ((ioc->facts.FWVersion.Struct.Major / 10) + '0') : '0';
  2178. karg.fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) + '0';
  2179. karg.fw_version[2] = '.';
  2180. karg.fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ?
  2181. ((ioc->facts.FWVersion.Struct.Minor / 10) + '0') : '0';
  2182. karg.fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) + '0';
  2183. karg.fw_version[5] = '.';
  2184. karg.fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ?
  2185. ((ioc->facts.FWVersion.Struct.Unit / 10) + '0') : '0';
  2186. karg.fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) + '0';
  2187. karg.fw_version[8] = '.';
  2188. karg.fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ?
  2189. ((ioc->facts.FWVersion.Struct.Dev / 10) + '0') : '0';
  2190. karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0';
  2191. karg.fw_version[11] = '\0';
  2192. /* Issue a config request to get the device serial number
  2193. */
  2194. hdr.PageVersion = 0;
  2195. hdr.PageLength = 0;
  2196. hdr.PageNumber = 0;
  2197. hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
  2198. cfg.cfghdr.hdr = &hdr;
  2199. cfg.physAddr = -1;
  2200. cfg.pageAddr = 0;
  2201. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  2202. cfg.dir = 0; /* read */
  2203. cfg.timeout = 10;
  2204. strncpy(karg.serial_number, " ", 24);
  2205. if (mpt_config(ioc, &cfg) == 0) {
  2206. if (cfg.cfghdr.hdr->PageLength > 0) {
  2207. /* Issue the second config page request */
  2208. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  2209. pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
  2210. if (pbuf) {
  2211. cfg.physAddr = buf_dma;
  2212. if (mpt_config(ioc, &cfg) == 0) {
  2213. ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf;
  2214. if (strlen(pdata->BoardTracerNumber) > 1) {
  2215. strncpy(karg.serial_number, pdata->BoardTracerNumber, 24);
  2216. karg.serial_number[24-1]='\0';
  2217. }
  2218. }
  2219. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
  2220. pbuf = NULL;
  2221. }
  2222. }
  2223. }
  2224. rc = mpt_GetIocState(ioc, 1);
  2225. switch (rc) {
  2226. case MPI_IOC_STATE_OPERATIONAL:
  2227. karg.ioc_status = HP_STATUS_OK;
  2228. break;
  2229. case MPI_IOC_STATE_FAULT:
  2230. karg.ioc_status = HP_STATUS_FAILED;
  2231. break;
  2232. case MPI_IOC_STATE_RESET:
  2233. case MPI_IOC_STATE_READY:
  2234. default:
  2235. karg.ioc_status = HP_STATUS_OTHER;
  2236. break;
  2237. }
  2238. karg.base_io_addr = pci_resource_start(pdev, 0);
  2239. if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
  2240. karg.bus_phys_width = HP_BUS_WIDTH_UNK;
  2241. else
  2242. karg.bus_phys_width = HP_BUS_WIDTH_16;
  2243. karg.hard_resets = 0;
  2244. karg.soft_resets = 0;
  2245. karg.timeouts = 0;
  2246. if (ioc->sh != NULL) {
  2247. MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  2248. if (hd && (cim_rev == 1)) {
  2249. karg.hard_resets = ioc->hard_resets;
  2250. karg.soft_resets = ioc->soft_resets;
  2251. karg.timeouts = ioc->timeouts;
  2252. }
  2253. }
  2254. /*
  2255. * Gather ISTWI(Industry Standard Two Wire Interface) Data
  2256. */
  2257. if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
  2258. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
  2259. "%s, no msg frames!!\n", ioc->name, __func__));
  2260. goto out;
  2261. }
  2262. IstwiRWRequest = (ToolboxIstwiReadWriteRequest_t *)mf;
  2263. msgcontext = IstwiRWRequest->MsgContext;
  2264. memset(IstwiRWRequest,0,sizeof(ToolboxIstwiReadWriteRequest_t));
  2265. IstwiRWRequest->MsgContext = msgcontext;
  2266. IstwiRWRequest->Function = MPI_FUNCTION_TOOLBOX;
  2267. IstwiRWRequest->Tool = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL;
  2268. IstwiRWRequest->Flags = MPI_TB_ISTWI_FLAGS_READ;
  2269. IstwiRWRequest->NumAddressBytes = 0x01;
  2270. IstwiRWRequest->DataLength = cpu_to_le16(0x04);
  2271. if (pdev->devfn & 1)
  2272. IstwiRWRequest->DeviceAddr = 0xB2;
  2273. else
  2274. IstwiRWRequest->DeviceAddr = 0xB0;
  2275. pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
  2276. if (!pbuf)
  2277. goto out;
  2278. ioc->add_sge((char *)&IstwiRWRequest->SGL,
  2279. (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma);
  2280. retval = 0;
  2281. SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
  2282. IstwiRWRequest->MsgContext);
  2283. INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
  2284. mpt_put_msg_frame(mptctl_id, ioc, mf);
  2285. retry_wait:
  2286. timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
  2287. HZ*MPT_IOCTL_DEFAULT_TIMEOUT);
  2288. if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  2289. retval = -ETIME;
  2290. printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name, __func__);
  2291. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
  2292. mpt_free_msg_frame(ioc, mf);
  2293. goto out;
  2294. }
  2295. if (!timeleft) {
  2296. printk(MYIOC_s_WARN_FMT
  2297. "HOST INFO command timeout, doorbell=0x%08x\n",
  2298. ioc->name, mpt_GetIocState(ioc, 0));
  2299. mptctl_timeout_expired(ioc, mf);
  2300. } else
  2301. goto retry_wait;
  2302. goto out;
  2303. }
  2304. /*
  2305. *ISTWI Data Definition
  2306. * pbuf[0] = FW_VERSION = 0x4
  2307. * pbuf[1] = Bay Count = 6 or 4 or 2, depending on
  2308. * the config, you should be seeing one out of these three values
  2309. * pbuf[2] = Drive Installed Map = bit pattern depend on which
  2310. * bays have drives in them
  2311. * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3)
  2312. */
  2313. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)
  2314. karg.rsvd = *(u32 *)pbuf;
  2315. out:
  2316. CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
  2317. SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
  2318. if (pbuf)
  2319. pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma);
  2320. /* Copy the data from kernel memory to user memory
  2321. */
  2322. if (copy_to_user((char __user *)arg, &karg, sizeof(hp_host_info_t))) {
  2323. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hpgethostinfo - "
  2324. "Unable to write out hp_host_info @ %p\n",
  2325. ioc->name, __FILE__, __LINE__, uarg);
  2326. return -EFAULT;
  2327. }
  2328. return 0;
  2329. }
  2330. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2331. /* Prototype Routine for the TARGET INFO command.
  2332. *
  2333. * Outputs: None.
  2334. * Return: 0 if successful
  2335. * -EFAULT if data unavailable
  2336. * -EBUSY if previous command timeout and IOC reset is not complete.
  2337. * -ENODEV if no such device/adapter
  2338. * -ETIME if timer expires
  2339. * -ENOMEM if memory allocation error
  2340. */
  2341. static int
  2342. mptctl_hp_targetinfo(unsigned long arg)
  2343. {
  2344. hp_target_info_t __user *uarg = (void __user *) arg;
  2345. SCSIDevicePage0_t *pg0_alloc;
  2346. SCSIDevicePage3_t *pg3_alloc;
  2347. MPT_ADAPTER *ioc;
  2348. MPT_SCSI_HOST *hd = NULL;
  2349. hp_target_info_t karg;
  2350. int iocnum;
  2351. int data_sz;
  2352. dma_addr_t page_dma;
  2353. CONFIGPARMS cfg;
  2354. ConfigPageHeader_t hdr;
  2355. int tmp, np, rc = 0;
  2356. if (copy_from_user(&karg, uarg, sizeof(hp_target_info_t))) {
  2357. printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_targetinfo - "
  2358. "Unable to read in hp_host_targetinfo struct @ %p\n",
  2359. __FILE__, __LINE__, uarg);
  2360. return -EFAULT;
  2361. }
  2362. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  2363. (ioc == NULL)) {
  2364. printk(KERN_DEBUG MYNAM "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
  2365. __FILE__, __LINE__, iocnum);
  2366. return -ENODEV;
  2367. }
  2368. if (karg.hdr.id >= MPT_MAX_FC_DEVICES)
  2369. return -EINVAL;
  2370. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_hp_targetinfo called.\n",
  2371. ioc->name));
  2372. /* There is nothing to do for FCP parts.
  2373. */
  2374. if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
  2375. return 0;
  2376. if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL))
  2377. return 0;
  2378. if (ioc->sh->host_no != karg.hdr.host)
  2379. return -ENODEV;
  2380. /* Get the data transfer speeds
  2381. */
  2382. data_sz = ioc->spi_data.sdp0length * 4;
  2383. pg0_alloc = (SCSIDevicePage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
  2384. if (pg0_alloc) {
  2385. hdr.PageVersion = ioc->spi_data.sdp0version;
  2386. hdr.PageLength = data_sz;
  2387. hdr.PageNumber = 0;
  2388. hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  2389. cfg.cfghdr.hdr = &hdr;
  2390. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  2391. cfg.dir = 0;
  2392. cfg.timeout = 0;
  2393. cfg.physAddr = page_dma;
  2394. cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
  2395. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  2396. np = le32_to_cpu(pg0_alloc->NegotiatedParameters);
  2397. karg.negotiated_width = np & MPI_SCSIDEVPAGE0_NP_WIDE ?
  2398. HP_BUS_WIDTH_16 : HP_BUS_WIDTH_8;
  2399. if (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) {
  2400. tmp = (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
  2401. if (tmp < 0x09)
  2402. karg.negotiated_speed = HP_DEV_SPEED_ULTRA320;
  2403. else if (tmp <= 0x09)
  2404. karg.negotiated_speed = HP_DEV_SPEED_ULTRA160;
  2405. else if (tmp <= 0x0A)
  2406. karg.negotiated_speed = HP_DEV_SPEED_ULTRA2;
  2407. else if (tmp <= 0x0C)
  2408. karg.negotiated_speed = HP_DEV_SPEED_ULTRA;
  2409. else if (tmp <= 0x25)
  2410. karg.negotiated_speed = HP_DEV_SPEED_FAST;
  2411. else
  2412. karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
  2413. } else
  2414. karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
  2415. }
  2416. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg0_alloc, page_dma);
  2417. }
  2418. /* Set defaults
  2419. */
  2420. karg.message_rejects = -1;
  2421. karg.phase_errors = -1;
  2422. karg.parity_errors = -1;
  2423. karg.select_timeouts = -1;
  2424. /* Get the target error parameters
  2425. */
  2426. hdr.PageVersion = 0;
  2427. hdr.PageLength = 0;
  2428. hdr.PageNumber = 3;
  2429. hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  2430. cfg.cfghdr.hdr = &hdr;
  2431. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  2432. cfg.dir = 0;
  2433. cfg.timeout = 0;
  2434. cfg.physAddr = -1;
  2435. if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) {
  2436. /* Issue the second config page request */
  2437. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  2438. data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
  2439. pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent(
  2440. ioc->pcidev, data_sz, &page_dma);
  2441. if (pg3_alloc) {
  2442. cfg.physAddr = page_dma;
  2443. cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
  2444. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  2445. karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount);
  2446. karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount);
  2447. karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount);
  2448. }
  2449. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg3_alloc, page_dma);
  2450. }
  2451. }
  2452. hd = shost_priv(ioc->sh);
  2453. if (hd != NULL)
  2454. karg.select_timeouts = hd->sel_timeout[karg.hdr.id];
  2455. /* Copy the data from kernel memory to user memory
  2456. */
  2457. if (copy_to_user((char __user *)arg, &karg, sizeof(hp_target_info_t))) {
  2458. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hp_target_info - "
  2459. "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
  2460. ioc->name, __FILE__, __LINE__, uarg);
  2461. return -EFAULT;
  2462. }
  2463. return 0;
  2464. }
  2465. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2466. static const struct file_operations mptctl_fops = {
  2467. .owner = THIS_MODULE,
  2468. .llseek = no_llseek,
  2469. .fasync = mptctl_fasync,
  2470. .unlocked_ioctl = mptctl_ioctl,
  2471. #ifdef CONFIG_COMPAT
  2472. .compat_ioctl = compat_mpctl_ioctl,
  2473. #endif
  2474. };
  2475. static struct miscdevice mptctl_miscdev = {
  2476. MPT_MINOR,
  2477. MYNAM,
  2478. &mptctl_fops
  2479. };
  2480. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2481. #ifdef CONFIG_COMPAT
  2482. static int
  2483. compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd,
  2484. unsigned long arg)
  2485. {
  2486. struct mpt_fw_xfer32 kfw32;
  2487. struct mpt_fw_xfer kfw;
  2488. MPT_ADAPTER *iocp = NULL;
  2489. int iocnum, iocnumX;
  2490. int nonblock = (filp->f_flags & O_NONBLOCK);
  2491. int ret;
  2492. if (copy_from_user(&kfw32, (char __user *)arg, sizeof(kfw32)))
  2493. return -EFAULT;
  2494. /* Verify intended MPT adapter */
  2495. iocnumX = kfw32.iocnum & 0xFF;
  2496. if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
  2497. (iocp == NULL)) {
  2498. printk(KERN_DEBUG MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
  2499. __LINE__, iocnumX);
  2500. return -ENODEV;
  2501. }
  2502. if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
  2503. return ret;
  2504. dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mptfwxfer_ioctl() called\n",
  2505. iocp->name));
  2506. kfw.iocnum = iocnum;
  2507. kfw.fwlen = kfw32.fwlen;
  2508. kfw.bufp = compat_ptr(kfw32.bufp);
  2509. ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen);
  2510. mutex_unlock(&iocp->ioctl_cmds.mutex);
  2511. return ret;
  2512. }
  2513. static int
  2514. compat_mpt_command(struct file *filp, unsigned int cmd,
  2515. unsigned long arg)
  2516. {
  2517. struct mpt_ioctl_command32 karg32;
  2518. struct mpt_ioctl_command32 __user *uarg = (struct mpt_ioctl_command32 __user *) arg;
  2519. struct mpt_ioctl_command karg;
  2520. MPT_ADAPTER *iocp = NULL;
  2521. int iocnum, iocnumX;
  2522. int nonblock = (filp->f_flags & O_NONBLOCK);
  2523. int ret;
  2524. if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32)))
  2525. return -EFAULT;
  2526. /* Verify intended MPT adapter */
  2527. iocnumX = karg32.hdr.iocnum & 0xFF;
  2528. if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
  2529. (iocp == NULL)) {
  2530. printk(KERN_DEBUG MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
  2531. __LINE__, iocnumX);
  2532. return -ENODEV;
  2533. }
  2534. if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
  2535. return ret;
  2536. dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mpt_command() called\n",
  2537. iocp->name));
  2538. /* Copy data to karg */
  2539. karg.hdr.iocnum = karg32.hdr.iocnum;
  2540. karg.hdr.port = karg32.hdr.port;
  2541. karg.timeout = karg32.timeout;
  2542. karg.maxReplyBytes = karg32.maxReplyBytes;
  2543. karg.dataInSize = karg32.dataInSize;
  2544. karg.dataOutSize = karg32.dataOutSize;
  2545. karg.maxSenseBytes = karg32.maxSenseBytes;
  2546. karg.dataSgeOffset = karg32.dataSgeOffset;
  2547. karg.replyFrameBufPtr = (char __user *)(unsigned long)karg32.replyFrameBufPtr;
  2548. karg.dataInBufPtr = (char __user *)(unsigned long)karg32.dataInBufPtr;
  2549. karg.dataOutBufPtr = (char __user *)(unsigned long)karg32.dataOutBufPtr;
  2550. karg.senseDataPtr = (char __user *)(unsigned long)karg32.senseDataPtr;
  2551. /* Pass new structure to do_mpt_command
  2552. */
  2553. ret = mptctl_do_mpt_command (karg, &uarg->MF);
  2554. mutex_unlock(&iocp->ioctl_cmds.mutex);
  2555. return ret;
  2556. }
  2557. static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
  2558. {
  2559. long ret;
  2560. mutex_lock(&mpctl_mutex);
  2561. switch (cmd) {
  2562. case MPTIOCINFO:
  2563. case MPTIOCINFO1:
  2564. case MPTIOCINFO2:
  2565. case MPTTARGETINFO:
  2566. case MPTEVENTQUERY:
  2567. case MPTEVENTENABLE:
  2568. case MPTEVENTREPORT:
  2569. case MPTHARDRESET:
  2570. case HP_GETHOSTINFO:
  2571. case HP_GETTARGETINFO:
  2572. case MPTTEST:
  2573. ret = __mptctl_ioctl(f, cmd, arg);
  2574. break;
  2575. case MPTCOMMAND32:
  2576. ret = compat_mpt_command(f, cmd, arg);
  2577. break;
  2578. case MPTFWDOWNLOAD32:
  2579. ret = compat_mptfwxfer_ioctl(f, cmd, arg);
  2580. break;
  2581. default:
  2582. ret = -ENOIOCTLCMD;
  2583. break;
  2584. }
  2585. mutex_unlock(&mpctl_mutex);
  2586. return ret;
  2587. }
  2588. #endif
  2589. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2590. /*
  2591. * mptctl_probe - Installs ioctl devices per bus.
  2592. * @pdev: Pointer to pci_dev structure
  2593. *
  2594. * Returns 0 for success, non-zero for failure.
  2595. *
  2596. */
  2597. static int
  2598. mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  2599. {
  2600. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  2601. mutex_init(&ioc->ioctl_cmds.mutex);
  2602. init_completion(&ioc->ioctl_cmds.done);
  2603. return 0;
  2604. }
  2605. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2606. /*
  2607. * mptctl_remove - Removed ioctl devices
  2608. * @pdev: Pointer to pci_dev structure
  2609. *
  2610. *
  2611. */
  2612. static void
  2613. mptctl_remove(struct pci_dev *pdev)
  2614. {
  2615. }
  2616. static struct mpt_pci_driver mptctl_driver = {
  2617. .probe = mptctl_probe,
  2618. .remove = mptctl_remove,
  2619. };
  2620. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2621. static int __init mptctl_init(void)
  2622. {
  2623. int err;
  2624. int where = 1;
  2625. show_mptmod_ver(my_NAME, my_VERSION);
  2626. mpt_device_driver_register(&mptctl_driver, MPTCTL_DRIVER);
  2627. /* Register this device */
  2628. err = misc_register(&mptctl_miscdev);
  2629. if (err < 0) {
  2630. printk(KERN_ERR MYNAM ": Can't register misc device [minor=%d].\n", MPT_MINOR);
  2631. goto out_fail;
  2632. }
  2633. printk(KERN_INFO MYNAM ": Registered with Fusion MPT base driver\n");
  2634. printk(KERN_INFO MYNAM ": /dev/%s @ (major,minor=%d,%d)\n",
  2635. mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
  2636. /*
  2637. * Install our handler
  2638. */
  2639. ++where;
  2640. mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER,
  2641. "mptctl_reply");
  2642. if (!mptctl_id || mptctl_id >= MPT_MAX_PROTOCOL_DRIVERS) {
  2643. printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
  2644. misc_deregister(&mptctl_miscdev);
  2645. err = -EBUSY;
  2646. goto out_fail;
  2647. }
  2648. mptctl_taskmgmt_id = mpt_register(mptctl_taskmgmt_reply, MPTCTL_DRIVER,
  2649. "mptctl_taskmgmt_reply");
  2650. if (!mptctl_taskmgmt_id || mptctl_taskmgmt_id >= MPT_MAX_PROTOCOL_DRIVERS) {
  2651. printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
  2652. mpt_deregister(mptctl_id);
  2653. misc_deregister(&mptctl_miscdev);
  2654. err = -EBUSY;
  2655. goto out_fail;
  2656. }
  2657. mpt_reset_register(mptctl_id, mptctl_ioc_reset);
  2658. mpt_event_register(mptctl_id, mptctl_event_process);
  2659. return 0;
  2660. out_fail:
  2661. mpt_device_driver_deregister(MPTCTL_DRIVER);
  2662. return err;
  2663. }
  2664. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2665. static void mptctl_exit(void)
  2666. {
  2667. misc_deregister(&mptctl_miscdev);
  2668. printk(KERN_INFO MYNAM ": Deregistered /dev/%s @ (major,minor=%d,%d)\n",
  2669. mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
  2670. /* De-register event handler from base module */
  2671. mpt_event_deregister(mptctl_id);
  2672. /* De-register reset handler from base module */
  2673. mpt_reset_deregister(mptctl_id);
  2674. /* De-register callback handler from base module */
  2675. mpt_deregister(mptctl_taskmgmt_id);
  2676. mpt_deregister(mptctl_id);
  2677. mpt_device_driver_deregister(MPTCTL_DRIVER);
  2678. }
  2679. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2680. module_init(mptctl_init);
  2681. module_exit(mptctl_exit);