mptctl.c 86 KB

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