mptctl.c 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088
  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. u8 revision;
  1101. struct scsi_device *sdev;
  1102. VirtDevice *vdevice;
  1103. /* Add of PCI INFO results in unaligned access for
  1104. * IA64 and Sparc. Reset long to int. Return no PCI
  1105. * data for obsolete format.
  1106. */
  1107. if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev0))
  1108. cim_rev = 0;
  1109. else if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev1))
  1110. cim_rev = 1;
  1111. else if (data_size == sizeof(struct mpt_ioctl_iocinfo))
  1112. cim_rev = 2;
  1113. else if (data_size == (sizeof(struct mpt_ioctl_iocinfo_rev0)+12))
  1114. cim_rev = 0; /* obsolete */
  1115. else
  1116. return -EFAULT;
  1117. karg = kmalloc(data_size, GFP_KERNEL);
  1118. if (karg == NULL) {
  1119. printk(KERN_ERR MYNAM "%s::mpt_ioctl_iocinfo() @%d - no memory available!\n",
  1120. __FILE__, __LINE__);
  1121. return -ENOMEM;
  1122. }
  1123. if (copy_from_user(karg, uarg, data_size)) {
  1124. printk(KERN_ERR MYNAM "%s@%d::mptctl_getiocinfo - "
  1125. "Unable to read in mpt_ioctl_iocinfo struct @ %p\n",
  1126. __FILE__, __LINE__, uarg);
  1127. kfree(karg);
  1128. return -EFAULT;
  1129. }
  1130. if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
  1131. (ioc == NULL)) {
  1132. printk(KERN_DEBUG MYNAM "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
  1133. __FILE__, __LINE__, iocnum);
  1134. kfree(karg);
  1135. return -ENODEV;
  1136. }
  1137. /* Verify the data transfer size is correct. */
  1138. if (karg->hdr.maxDataSize != data_size) {
  1139. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
  1140. "Structure size mismatch. Command not completed.\n",
  1141. ioc->name, __FILE__, __LINE__);
  1142. kfree(karg);
  1143. return -EFAULT;
  1144. }
  1145. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_getiocinfo called.\n",
  1146. ioc->name));
  1147. /* Fill in the data and return the structure to the calling
  1148. * program
  1149. */
  1150. if (ioc->bus_type == SAS)
  1151. karg->adapterType = MPT_IOCTL_INTERFACE_SAS;
  1152. else if (ioc->bus_type == FC)
  1153. karg->adapterType = MPT_IOCTL_INTERFACE_FC;
  1154. else
  1155. karg->adapterType = MPT_IOCTL_INTERFACE_SCSI;
  1156. if (karg->hdr.port > 1) {
  1157. kfree(karg);
  1158. return -EINVAL;
  1159. }
  1160. port = karg->hdr.port;
  1161. karg->port = port;
  1162. pdev = (struct pci_dev *) ioc->pcidev;
  1163. karg->pciId = pdev->device;
  1164. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  1165. karg->hwRev = revision;
  1166. karg->subSystemDevice = pdev->subsystem_device;
  1167. karg->subSystemVendor = pdev->subsystem_vendor;
  1168. if (cim_rev == 1) {
  1169. /* Get the PCI bus, device, and function numbers for the IOC
  1170. */
  1171. karg->pciInfo.u.bits.busNumber = pdev->bus->number;
  1172. karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
  1173. karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
  1174. } else if (cim_rev == 2) {
  1175. /* Get the PCI bus, device, function and segment ID numbers
  1176. for the IOC */
  1177. karg->pciInfo.u.bits.busNumber = pdev->bus->number;
  1178. karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
  1179. karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
  1180. karg->pciInfo.segmentID = pci_domain_nr(pdev->bus);
  1181. }
  1182. /* Get number of devices
  1183. */
  1184. karg->numDevices = 0;
  1185. if (ioc->sh) {
  1186. shost_for_each_device(sdev, ioc->sh) {
  1187. vdevice = sdev->hostdata;
  1188. if (vdevice == NULL || vdevice->vtarget == NULL)
  1189. continue;
  1190. if (vdevice->vtarget->tflags &
  1191. MPT_TARGET_FLAGS_RAID_COMPONENT)
  1192. continue;
  1193. karg->numDevices++;
  1194. }
  1195. }
  1196. /* Set the BIOS and FW Version
  1197. */
  1198. karg->FWVersion = ioc->facts.FWVersion.Word;
  1199. karg->BIOSVersion = ioc->biosVersion;
  1200. /* Set the Version Strings.
  1201. */
  1202. strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH);
  1203. karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0';
  1204. karg->busChangeEvent = 0;
  1205. karg->hostId = ioc->pfacts[port].PortSCSIID;
  1206. karg->rsvd[0] = karg->rsvd[1] = 0;
  1207. /* Copy the data from kernel memory to user memory
  1208. */
  1209. if (copy_to_user((char __user *)arg, karg, data_size)) {
  1210. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
  1211. "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
  1212. ioc->name, __FILE__, __LINE__, uarg);
  1213. kfree(karg);
  1214. return -EFAULT;
  1215. }
  1216. kfree(karg);
  1217. return 0;
  1218. }
  1219. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1220. /*
  1221. * mptctl_gettargetinfo - Query the host adapter for target information.
  1222. * @arg: User space argument
  1223. *
  1224. * Outputs: None.
  1225. * Return: 0 if successful
  1226. * -EFAULT if data unavailable
  1227. * -ENODEV if no such device/adapter
  1228. */
  1229. static int
  1230. mptctl_gettargetinfo (unsigned long arg)
  1231. {
  1232. struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg;
  1233. struct mpt_ioctl_targetinfo karg;
  1234. MPT_ADAPTER *ioc;
  1235. VirtDevice *vdevice;
  1236. char *pmem;
  1237. int *pdata;
  1238. int iocnum;
  1239. int numDevices = 0;
  1240. int lun;
  1241. int maxWordsLeft;
  1242. int numBytes;
  1243. u8 port;
  1244. struct scsi_device *sdev;
  1245. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) {
  1246. printk(KERN_ERR MYNAM "%s@%d::mptctl_gettargetinfo - "
  1247. "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
  1248. __FILE__, __LINE__, uarg);
  1249. return -EFAULT;
  1250. }
  1251. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1252. (ioc == NULL)) {
  1253. printk(KERN_DEBUG MYNAM "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
  1254. __FILE__, __LINE__, iocnum);
  1255. return -ENODEV;
  1256. }
  1257. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_gettargetinfo called.\n",
  1258. ioc->name));
  1259. /* Get the port number and set the maximum number of bytes
  1260. * in the returned structure.
  1261. * Ignore the port setting.
  1262. */
  1263. numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
  1264. maxWordsLeft = numBytes/sizeof(int);
  1265. port = karg.hdr.port;
  1266. if (maxWordsLeft <= 0) {
  1267. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
  1268. ioc->name, __FILE__, __LINE__);
  1269. return -ENOMEM;
  1270. }
  1271. /* Fill in the data and return the structure to the calling
  1272. * program
  1273. */
  1274. /* struct mpt_ioctl_targetinfo does not contain sufficient space
  1275. * for the target structures so when the IOCTL is called, there is
  1276. * not sufficient stack space for the structure. Allocate memory,
  1277. * populate the memory, copy back to the user, then free memory.
  1278. * targetInfo format:
  1279. * bits 31-24: reserved
  1280. * 23-16: LUN
  1281. * 15- 8: Bus Number
  1282. * 7- 0: Target ID
  1283. */
  1284. pmem = kzalloc(numBytes, GFP_KERNEL);
  1285. if (!pmem) {
  1286. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
  1287. ioc->name, __FILE__, __LINE__);
  1288. return -ENOMEM;
  1289. }
  1290. pdata = (int *) pmem;
  1291. /* Get number of devices
  1292. */
  1293. if (ioc->sh){
  1294. shost_for_each_device(sdev, ioc->sh) {
  1295. if (!maxWordsLeft)
  1296. continue;
  1297. vdevice = sdev->hostdata;
  1298. if (vdevice == NULL || vdevice->vtarget == NULL)
  1299. continue;
  1300. if (vdevice->vtarget->tflags &
  1301. MPT_TARGET_FLAGS_RAID_COMPONENT)
  1302. continue;
  1303. lun = (vdevice->vtarget->raidVolume) ? 0x80 : vdevice->lun;
  1304. *pdata = (((u8)lun << 16) + (vdevice->vtarget->channel << 8) +
  1305. (vdevice->vtarget->id ));
  1306. pdata++;
  1307. numDevices++;
  1308. --maxWordsLeft;
  1309. }
  1310. }
  1311. karg.numDevices = numDevices;
  1312. /* Copy part of the data from kernel memory to user memory
  1313. */
  1314. if (copy_to_user((char __user *)arg, &karg,
  1315. sizeof(struct mpt_ioctl_targetinfo))) {
  1316. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - "
  1317. "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
  1318. ioc->name, __FILE__, __LINE__, uarg);
  1319. kfree(pmem);
  1320. return -EFAULT;
  1321. }
  1322. /* Copy the remaining data from kernel memory to user memory
  1323. */
  1324. if (copy_to_user(uarg->targetInfo, pmem, numBytes)) {
  1325. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - "
  1326. "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
  1327. ioc->name, __FILE__, __LINE__, pdata);
  1328. kfree(pmem);
  1329. return -EFAULT;
  1330. }
  1331. kfree(pmem);
  1332. return 0;
  1333. }
  1334. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1335. /* MPT IOCTL Test function.
  1336. *
  1337. * Outputs: None.
  1338. * Return: 0 if successful
  1339. * -EFAULT if data unavailable
  1340. * -ENODEV if no such device/adapter
  1341. */
  1342. static int
  1343. mptctl_readtest (unsigned long arg)
  1344. {
  1345. struct mpt_ioctl_test __user *uarg = (void __user *) arg;
  1346. struct mpt_ioctl_test karg;
  1347. MPT_ADAPTER *ioc;
  1348. int iocnum;
  1349. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_test))) {
  1350. printk(KERN_ERR MYNAM "%s@%d::mptctl_readtest - "
  1351. "Unable to read in mpt_ioctl_test struct @ %p\n",
  1352. __FILE__, __LINE__, uarg);
  1353. return -EFAULT;
  1354. }
  1355. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1356. (ioc == NULL)) {
  1357. printk(KERN_DEBUG MYNAM "%s::mptctl_readtest() @%d - ioc%d not found!\n",
  1358. __FILE__, __LINE__, iocnum);
  1359. return -ENODEV;
  1360. }
  1361. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_readtest called.\n",
  1362. ioc->name));
  1363. /* Fill in the data and return the structure to the calling
  1364. * program
  1365. */
  1366. #ifdef MFCNT
  1367. karg.chip_type = ioc->mfcnt;
  1368. #else
  1369. karg.chip_type = ioc->pcidev->device;
  1370. #endif
  1371. strncpy (karg.name, ioc->name, MPT_MAX_NAME);
  1372. karg.name[MPT_MAX_NAME-1]='\0';
  1373. strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH);
  1374. karg.product[MPT_PRODUCT_LENGTH-1]='\0';
  1375. /* Copy the data from kernel memory to user memory
  1376. */
  1377. if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_test))) {
  1378. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_readtest - "
  1379. "Unable to write out mpt_ioctl_test struct @ %p\n",
  1380. ioc->name, __FILE__, __LINE__, uarg);
  1381. return -EFAULT;
  1382. }
  1383. return 0;
  1384. }
  1385. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1386. /*
  1387. * mptctl_eventquery - Query the host adapter for the event types
  1388. * that are being logged.
  1389. * @arg: User space argument
  1390. *
  1391. * Outputs: None.
  1392. * Return: 0 if successful
  1393. * -EFAULT if data unavailable
  1394. * -ENODEV if no such device/adapter
  1395. */
  1396. static int
  1397. mptctl_eventquery (unsigned long arg)
  1398. {
  1399. struct mpt_ioctl_eventquery __user *uarg = (void __user *) arg;
  1400. struct mpt_ioctl_eventquery karg;
  1401. MPT_ADAPTER *ioc;
  1402. int iocnum;
  1403. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventquery))) {
  1404. printk(KERN_ERR MYNAM "%s@%d::mptctl_eventquery - "
  1405. "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
  1406. __FILE__, __LINE__, uarg);
  1407. return -EFAULT;
  1408. }
  1409. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1410. (ioc == NULL)) {
  1411. printk(KERN_DEBUG MYNAM "%s::mptctl_eventquery() @%d - ioc%d not found!\n",
  1412. __FILE__, __LINE__, iocnum);
  1413. return -ENODEV;
  1414. }
  1415. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventquery called.\n",
  1416. ioc->name));
  1417. karg.eventEntries = MPTCTL_EVENT_LOG_SIZE;
  1418. karg.eventTypes = ioc->eventTypes;
  1419. /* Copy the data from kernel memory to user memory
  1420. */
  1421. if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_eventquery))) {
  1422. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventquery - "
  1423. "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
  1424. ioc->name, __FILE__, __LINE__, uarg);
  1425. return -EFAULT;
  1426. }
  1427. return 0;
  1428. }
  1429. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1430. static int
  1431. mptctl_eventenable (unsigned long arg)
  1432. {
  1433. struct mpt_ioctl_eventenable __user *uarg = (void __user *) arg;
  1434. struct mpt_ioctl_eventenable karg;
  1435. MPT_ADAPTER *ioc;
  1436. int iocnum;
  1437. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventenable))) {
  1438. printk(KERN_ERR MYNAM "%s@%d::mptctl_eventenable - "
  1439. "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
  1440. __FILE__, __LINE__, uarg);
  1441. return -EFAULT;
  1442. }
  1443. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1444. (ioc == NULL)) {
  1445. printk(KERN_DEBUG MYNAM "%s::mptctl_eventenable() @%d - ioc%d not found!\n",
  1446. __FILE__, __LINE__, iocnum);
  1447. return -ENODEV;
  1448. }
  1449. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventenable called.\n",
  1450. ioc->name));
  1451. if (ioc->events == NULL) {
  1452. /* Have not yet allocated memory - do so now.
  1453. */
  1454. int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
  1455. ioc->events = kzalloc(sz, GFP_KERNEL);
  1456. if (!ioc->events) {
  1457. printk(MYIOC_s_ERR_FMT
  1458. ": ERROR - Insufficient memory to add adapter!\n",
  1459. ioc->name);
  1460. return -ENOMEM;
  1461. }
  1462. ioc->alloc_total += sz;
  1463. ioc->eventContext = 0;
  1464. }
  1465. /* Update the IOC event logging flag.
  1466. */
  1467. ioc->eventTypes = karg.eventTypes;
  1468. return 0;
  1469. }
  1470. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1471. static int
  1472. mptctl_eventreport (unsigned long arg)
  1473. {
  1474. struct mpt_ioctl_eventreport __user *uarg = (void __user *) arg;
  1475. struct mpt_ioctl_eventreport karg;
  1476. MPT_ADAPTER *ioc;
  1477. int iocnum;
  1478. int numBytes, maxEvents, max;
  1479. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventreport))) {
  1480. printk(KERN_ERR MYNAM "%s@%d::mptctl_eventreport - "
  1481. "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
  1482. __FILE__, __LINE__, uarg);
  1483. return -EFAULT;
  1484. }
  1485. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1486. (ioc == NULL)) {
  1487. printk(KERN_DEBUG MYNAM "%s::mptctl_eventreport() @%d - ioc%d not found!\n",
  1488. __FILE__, __LINE__, iocnum);
  1489. return -ENODEV;
  1490. }
  1491. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventreport called.\n",
  1492. ioc->name));
  1493. numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
  1494. maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS);
  1495. max = MPTCTL_EVENT_LOG_SIZE < maxEvents ? MPTCTL_EVENT_LOG_SIZE : maxEvents;
  1496. /* If fewer than 1 event is requested, there must have
  1497. * been some type of error.
  1498. */
  1499. if ((max < 1) || !ioc->events)
  1500. return -ENODATA;
  1501. /* reset this flag so SIGIO can restart */
  1502. ioc->aen_event_read_flag=0;
  1503. /* Copy the data from kernel memory to user memory
  1504. */
  1505. numBytes = max * sizeof(MPT_IOCTL_EVENTS);
  1506. if (copy_to_user(uarg->eventData, ioc->events, numBytes)) {
  1507. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventreport - "
  1508. "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
  1509. ioc->name, __FILE__, __LINE__, ioc->events);
  1510. return -EFAULT;
  1511. }
  1512. return 0;
  1513. }
  1514. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1515. static int
  1516. mptctl_replace_fw (unsigned long arg)
  1517. {
  1518. struct mpt_ioctl_replace_fw __user *uarg = (void __user *) arg;
  1519. struct mpt_ioctl_replace_fw karg;
  1520. MPT_ADAPTER *ioc;
  1521. int iocnum;
  1522. int newFwSize;
  1523. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) {
  1524. printk(KERN_ERR MYNAM "%s@%d::mptctl_replace_fw - "
  1525. "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
  1526. __FILE__, __LINE__, uarg);
  1527. return -EFAULT;
  1528. }
  1529. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1530. (ioc == NULL)) {
  1531. printk(KERN_DEBUG MYNAM "%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
  1532. __FILE__, __LINE__, iocnum);
  1533. return -ENODEV;
  1534. }
  1535. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_replace_fw called.\n",
  1536. ioc->name));
  1537. /* If caching FW, Free the old FW image
  1538. */
  1539. if (ioc->cached_fw == NULL)
  1540. return 0;
  1541. mpt_free_fw_memory(ioc);
  1542. /* Allocate memory for the new FW image
  1543. */
  1544. newFwSize = karg.newImageSize;
  1545. if (newFwSize & 0x01)
  1546. newFwSize += 1;
  1547. if (newFwSize & 0x02)
  1548. newFwSize += 2;
  1549. mpt_alloc_fw_memory(ioc, newFwSize);
  1550. if (ioc->cached_fw == NULL)
  1551. return -ENOMEM;
  1552. /* Copy the data from user memory to kernel space
  1553. */
  1554. if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {
  1555. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_replace_fw - "
  1556. "Unable to read in mpt_ioctl_replace_fw image "
  1557. "@ %p\n", ioc->name, __FILE__, __LINE__, uarg);
  1558. mpt_free_fw_memory(ioc);
  1559. return -EFAULT;
  1560. }
  1561. /* Update IOCFactsReply
  1562. */
  1563. ioc->facts.FWImageSize = newFwSize;
  1564. return 0;
  1565. }
  1566. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1567. /* MPT IOCTL MPTCOMMAND function.
  1568. * Cast the arg into the mpt_ioctl_mpt_command structure.
  1569. *
  1570. * Outputs: None.
  1571. * Return: 0 if successful
  1572. * -EBUSY if previous command timeout and IOC reset is not complete.
  1573. * -EFAULT if data unavailable
  1574. * -ENODEV if no such device/adapter
  1575. * -ETIME if timer expires
  1576. * -ENOMEM if memory allocation error
  1577. */
  1578. static int
  1579. mptctl_mpt_command (unsigned long arg)
  1580. {
  1581. struct mpt_ioctl_command __user *uarg = (void __user *) arg;
  1582. struct mpt_ioctl_command karg;
  1583. MPT_ADAPTER *ioc;
  1584. int iocnum;
  1585. int rc;
  1586. if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_command))) {
  1587. printk(KERN_ERR MYNAM "%s@%d::mptctl_mpt_command - "
  1588. "Unable to read in mpt_ioctl_command struct @ %p\n",
  1589. __FILE__, __LINE__, uarg);
  1590. return -EFAULT;
  1591. }
  1592. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1593. (ioc == NULL)) {
  1594. printk(KERN_DEBUG MYNAM "%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
  1595. __FILE__, __LINE__, iocnum);
  1596. return -ENODEV;
  1597. }
  1598. rc = mptctl_do_mpt_command (karg, &uarg->MF);
  1599. return rc;
  1600. }
  1601. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1602. /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands.
  1603. *
  1604. * Outputs: None.
  1605. * Return: 0 if successful
  1606. * -EBUSY if previous command timeout and IOC reset is not complete.
  1607. * -EFAULT if data unavailable
  1608. * -ENODEV if no such device/adapter
  1609. * -ETIME if timer expires
  1610. * -ENOMEM if memory allocation error
  1611. * -EPERM if SCSI I/O and target is untagged
  1612. */
  1613. static int
  1614. mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
  1615. {
  1616. MPT_ADAPTER *ioc;
  1617. MPT_FRAME_HDR *mf = NULL;
  1618. MPIHeader_t *hdr;
  1619. char *psge;
  1620. struct buflist bufIn; /* data In buffer */
  1621. struct buflist bufOut; /* data Out buffer */
  1622. dma_addr_t dma_addr_in;
  1623. dma_addr_t dma_addr_out;
  1624. int sgSize = 0; /* Num SG elements */
  1625. int iocnum, flagsLength;
  1626. int sz, rc = 0;
  1627. int msgContext;
  1628. u16 req_idx;
  1629. ulong timeout;
  1630. unsigned long timeleft;
  1631. struct scsi_device *sdev;
  1632. unsigned long flags;
  1633. u8 function;
  1634. /* bufIn and bufOut are used for user to kernel space transfers
  1635. */
  1636. bufIn.kptr = bufOut.kptr = NULL;
  1637. bufIn.len = bufOut.len = 0;
  1638. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  1639. (ioc == NULL)) {
  1640. printk(KERN_DEBUG MYNAM "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
  1641. __FILE__, __LINE__, iocnum);
  1642. return -ENODEV;
  1643. }
  1644. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  1645. if (ioc->ioc_reset_in_progress) {
  1646. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  1647. printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - "
  1648. "Busy with diagnostic reset\n", __FILE__, __LINE__);
  1649. return -EBUSY;
  1650. }
  1651. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  1652. /* Verify that the final request frame will not be too large.
  1653. */
  1654. sz = karg.dataSgeOffset * 4;
  1655. if (karg.dataInSize > 0)
  1656. sz += ioc->SGE_size;
  1657. if (karg.dataOutSize > 0)
  1658. sz += ioc->SGE_size;
  1659. if (sz > ioc->req_sz) {
  1660. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1661. "Request frame too large (%d) maximum (%d)\n",
  1662. ioc->name, __FILE__, __LINE__, sz, ioc->req_sz);
  1663. return -EFAULT;
  1664. }
  1665. /* Get a free request frame and save the message context.
  1666. */
  1667. if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
  1668. return -EAGAIN;
  1669. hdr = (MPIHeader_t *) mf;
  1670. msgContext = le32_to_cpu(hdr->MsgContext);
  1671. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  1672. /* Copy the request frame
  1673. * Reset the saved message context.
  1674. * Request frame in user space
  1675. */
  1676. if (copy_from_user(mf, mfPtr, karg.dataSgeOffset * 4)) {
  1677. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1678. "Unable to read MF from mpt_ioctl_command struct @ %p\n",
  1679. ioc->name, __FILE__, __LINE__, mfPtr);
  1680. function = -1;
  1681. rc = -EFAULT;
  1682. goto done_free_mem;
  1683. }
  1684. hdr->MsgContext = cpu_to_le32(msgContext);
  1685. function = hdr->Function;
  1686. /* Verify that this request is allowed.
  1687. */
  1688. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sending mpi function (0x%02X), req=%p\n",
  1689. ioc->name, hdr->Function, mf));
  1690. switch (function) {
  1691. case MPI_FUNCTION_IOC_FACTS:
  1692. case MPI_FUNCTION_PORT_FACTS:
  1693. karg.dataOutSize = karg.dataInSize = 0;
  1694. break;
  1695. case MPI_FUNCTION_CONFIG:
  1696. {
  1697. Config_t *config_frame;
  1698. config_frame = (Config_t *)mf;
  1699. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\ttype=0x%02x ext_type=0x%02x "
  1700. "number=0x%02x action=0x%02x\n", ioc->name,
  1701. config_frame->Header.PageType,
  1702. config_frame->ExtPageType,
  1703. config_frame->Header.PageNumber,
  1704. config_frame->Action));
  1705. break;
  1706. }
  1707. case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND:
  1708. case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND:
  1709. case MPI_FUNCTION_FW_UPLOAD:
  1710. case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
  1711. case MPI_FUNCTION_FW_DOWNLOAD:
  1712. case MPI_FUNCTION_FC_PRIMITIVE_SEND:
  1713. case MPI_FUNCTION_TOOLBOX:
  1714. case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
  1715. break;
  1716. case MPI_FUNCTION_SCSI_IO_REQUEST:
  1717. if (ioc->sh) {
  1718. SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
  1719. int qtag = MPI_SCSIIO_CONTROL_UNTAGGED;
  1720. int scsidir = 0;
  1721. int dataSize;
  1722. u32 id;
  1723. id = (ioc->devices_per_bus == 0) ? 256 : ioc->devices_per_bus;
  1724. if (pScsiReq->TargetID > id) {
  1725. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1726. "Target ID out of bounds. \n",
  1727. ioc->name, __FILE__, __LINE__);
  1728. rc = -ENODEV;
  1729. goto done_free_mem;
  1730. }
  1731. if (pScsiReq->Bus >= ioc->number_of_buses) {
  1732. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1733. "Target Bus out of bounds. \n",
  1734. ioc->name, __FILE__, __LINE__);
  1735. rc = -ENODEV;
  1736. goto done_free_mem;
  1737. }
  1738. pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
  1739. pScsiReq->MsgFlags |= mpt_msg_flags(ioc);
  1740. /* verify that app has not requested
  1741. * more sense data than driver
  1742. * can provide, if so, reset this parameter
  1743. * set the sense buffer pointer low address
  1744. * update the control field to specify Q type
  1745. */
  1746. if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
  1747. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  1748. else
  1749. pScsiReq->SenseBufferLength = karg.maxSenseBytes;
  1750. pScsiReq->SenseBufferLowAddr =
  1751. cpu_to_le32(ioc->sense_buf_low_dma
  1752. + (req_idx * MPT_SENSE_BUFFER_ALLOC));
  1753. shost_for_each_device(sdev, ioc->sh) {
  1754. struct scsi_target *starget = scsi_target(sdev);
  1755. VirtTarget *vtarget = starget->hostdata;
  1756. if (vtarget == NULL)
  1757. continue;
  1758. if ((pScsiReq->TargetID == vtarget->id) &&
  1759. (pScsiReq->Bus == vtarget->channel) &&
  1760. (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
  1761. qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
  1762. }
  1763. /* Have the IOCTL driver set the direction based
  1764. * on the dataOutSize (ordering issue with Sparc).
  1765. */
  1766. if (karg.dataOutSize > 0) {
  1767. scsidir = MPI_SCSIIO_CONTROL_WRITE;
  1768. dataSize = karg.dataOutSize;
  1769. } else {
  1770. scsidir = MPI_SCSIIO_CONTROL_READ;
  1771. dataSize = karg.dataInSize;
  1772. }
  1773. pScsiReq->Control = cpu_to_le32(scsidir | qtag);
  1774. pScsiReq->DataLength = cpu_to_le32(dataSize);
  1775. } else {
  1776. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1777. "SCSI driver is not loaded. \n",
  1778. ioc->name, __FILE__, __LINE__);
  1779. rc = -EFAULT;
  1780. goto done_free_mem;
  1781. }
  1782. break;
  1783. case MPI_FUNCTION_SMP_PASSTHROUGH:
  1784. /* Check mf->PassthruFlags to determine if
  1785. * transfer is ImmediateMode or not.
  1786. * Immediate mode returns data in the ReplyFrame.
  1787. * Else, we are sending request and response data
  1788. * in two SGLs at the end of the mf.
  1789. */
  1790. break;
  1791. case MPI_FUNCTION_SATA_PASSTHROUGH:
  1792. if (!ioc->sh) {
  1793. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1794. "SCSI driver is not loaded. \n",
  1795. ioc->name, __FILE__, __LINE__);
  1796. rc = -EFAULT;
  1797. goto done_free_mem;
  1798. }
  1799. break;
  1800. case MPI_FUNCTION_RAID_ACTION:
  1801. /* Just add a SGE
  1802. */
  1803. break;
  1804. case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
  1805. if (ioc->sh) {
  1806. SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
  1807. int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
  1808. int scsidir = MPI_SCSIIO_CONTROL_READ;
  1809. int dataSize;
  1810. pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
  1811. pScsiReq->MsgFlags |= mpt_msg_flags(ioc);
  1812. /* verify that app has not requested
  1813. * more sense data than driver
  1814. * can provide, if so, reset this parameter
  1815. * set the sense buffer pointer low address
  1816. * update the control field to specify Q type
  1817. */
  1818. if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
  1819. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  1820. else
  1821. pScsiReq->SenseBufferLength = karg.maxSenseBytes;
  1822. pScsiReq->SenseBufferLowAddr =
  1823. cpu_to_le32(ioc->sense_buf_low_dma
  1824. + (req_idx * MPT_SENSE_BUFFER_ALLOC));
  1825. /* All commands to physical devices are tagged
  1826. */
  1827. /* Have the IOCTL driver set the direction based
  1828. * on the dataOutSize (ordering issue with Sparc).
  1829. */
  1830. if (karg.dataOutSize > 0) {
  1831. scsidir = MPI_SCSIIO_CONTROL_WRITE;
  1832. dataSize = karg.dataOutSize;
  1833. } else {
  1834. scsidir = MPI_SCSIIO_CONTROL_READ;
  1835. dataSize = karg.dataInSize;
  1836. }
  1837. pScsiReq->Control = cpu_to_le32(scsidir | qtag);
  1838. pScsiReq->DataLength = cpu_to_le32(dataSize);
  1839. } else {
  1840. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1841. "SCSI driver is not loaded. \n",
  1842. ioc->name, __FILE__, __LINE__);
  1843. rc = -EFAULT;
  1844. goto done_free_mem;
  1845. }
  1846. break;
  1847. case MPI_FUNCTION_SCSI_TASK_MGMT:
  1848. {
  1849. SCSITaskMgmt_t *pScsiTm;
  1850. pScsiTm = (SCSITaskMgmt_t *)mf;
  1851. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1852. "\tTaskType=0x%x MsgFlags=0x%x "
  1853. "TaskMsgContext=0x%x id=%d channel=%d\n",
  1854. ioc->name, pScsiTm->TaskType, le32_to_cpu
  1855. (pScsiTm->TaskMsgContext), pScsiTm->MsgFlags,
  1856. pScsiTm->TargetID, pScsiTm->Bus));
  1857. break;
  1858. }
  1859. case MPI_FUNCTION_IOC_INIT:
  1860. {
  1861. IOCInit_t *pInit = (IOCInit_t *) mf;
  1862. u32 high_addr, sense_high;
  1863. /* Verify that all entries in the IOC INIT match
  1864. * existing setup (and in LE format).
  1865. */
  1866. if (sizeof(dma_addr_t) == sizeof(u64)) {
  1867. high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32));
  1868. sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
  1869. } else {
  1870. high_addr = 0;
  1871. sense_high= 0;
  1872. }
  1873. if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) ||
  1874. (pInit->MaxBuses != ioc->facts.MaxBuses) ||
  1875. (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) ||
  1876. (pInit->HostMfaHighAddr != high_addr) ||
  1877. (pInit->SenseBufferHighAddr != sense_high)) {
  1878. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1879. "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
  1880. ioc->name, __FILE__, __LINE__);
  1881. rc = -EFAULT;
  1882. goto done_free_mem;
  1883. }
  1884. }
  1885. break;
  1886. default:
  1887. /*
  1888. * MPI_FUNCTION_PORT_ENABLE
  1889. * MPI_FUNCTION_TARGET_CMD_BUFFER_POST
  1890. * MPI_FUNCTION_TARGET_ASSIST
  1891. * MPI_FUNCTION_TARGET_STATUS_SEND
  1892. * MPI_FUNCTION_TARGET_MODE_ABORT
  1893. * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
  1894. * MPI_FUNCTION_IO_UNIT_RESET
  1895. * MPI_FUNCTION_HANDSHAKE
  1896. * MPI_FUNCTION_REPLY_FRAME_REMOVAL
  1897. * MPI_FUNCTION_EVENT_NOTIFICATION
  1898. * (driver handles event notification)
  1899. * MPI_FUNCTION_EVENT_ACK
  1900. */
  1901. /* What to do with these??? CHECK ME!!!
  1902. MPI_FUNCTION_FC_LINK_SRVC_BUF_POST
  1903. MPI_FUNCTION_FC_LINK_SRVC_RSP
  1904. MPI_FUNCTION_FC_ABORT
  1905. MPI_FUNCTION_LAN_SEND
  1906. MPI_FUNCTION_LAN_RECEIVE
  1907. MPI_FUNCTION_LAN_RESET
  1908. */
  1909. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  1910. "Illegal request (function 0x%x) \n",
  1911. ioc->name, __FILE__, __LINE__, hdr->Function);
  1912. rc = -EFAULT;
  1913. goto done_free_mem;
  1914. }
  1915. /* Add the SGL ( at most one data in SGE and one data out SGE )
  1916. * In the case of two SGE's - the data out (write) will always
  1917. * preceede the data in (read) SGE. psgList is used to free the
  1918. * allocated memory.
  1919. */
  1920. psge = (char *) (((int *) mf) + karg.dataSgeOffset);
  1921. flagsLength = 0;
  1922. if (karg.dataOutSize > 0)
  1923. sgSize ++;
  1924. if (karg.dataInSize > 0)
  1925. sgSize ++;
  1926. if (sgSize > 0) {
  1927. /* Set up the dataOut memory allocation */
  1928. if (karg.dataOutSize > 0) {
  1929. if (karg.dataInSize > 0) {
  1930. flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
  1931. MPI_SGE_FLAGS_END_OF_BUFFER |
  1932. MPI_SGE_FLAGS_DIRECTION)
  1933. << MPI_SGE_FLAGS_SHIFT;
  1934. } else {
  1935. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
  1936. }
  1937. flagsLength |= karg.dataOutSize;
  1938. bufOut.len = karg.dataOutSize;
  1939. bufOut.kptr = pci_alloc_consistent(
  1940. ioc->pcidev, bufOut.len, &dma_addr_out);
  1941. if (bufOut.kptr == NULL) {
  1942. rc = -ENOMEM;
  1943. goto done_free_mem;
  1944. } else {
  1945. /* Set up this SGE.
  1946. * Copy to MF and to sglbuf
  1947. */
  1948. ioc->add_sge(psge, flagsLength, dma_addr_out);
  1949. psge += ioc->SGE_size;
  1950. /* Copy user data to kernel space.
  1951. */
  1952. if (copy_from_user(bufOut.kptr,
  1953. karg.dataOutBufPtr,
  1954. bufOut.len)) {
  1955. printk(MYIOC_s_ERR_FMT
  1956. "%s@%d::mptctl_do_mpt_command - Unable "
  1957. "to read user data "
  1958. "struct @ %p\n",
  1959. ioc->name, __FILE__, __LINE__,karg.dataOutBufPtr);
  1960. rc = -EFAULT;
  1961. goto done_free_mem;
  1962. }
  1963. }
  1964. }
  1965. if (karg.dataInSize > 0) {
  1966. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
  1967. flagsLength |= karg.dataInSize;
  1968. bufIn.len = karg.dataInSize;
  1969. bufIn.kptr = pci_alloc_consistent(ioc->pcidev,
  1970. bufIn.len, &dma_addr_in);
  1971. if (bufIn.kptr == NULL) {
  1972. rc = -ENOMEM;
  1973. goto done_free_mem;
  1974. } else {
  1975. /* Set up this SGE
  1976. * Copy to MF and to sglbuf
  1977. */
  1978. ioc->add_sge(psge, flagsLength, dma_addr_in);
  1979. }
  1980. }
  1981. } else {
  1982. /* Add a NULL SGE
  1983. */
  1984. ioc->add_sge(psge, flagsLength, (dma_addr_t) -1);
  1985. }
  1986. SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, hdr->MsgContext);
  1987. INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
  1988. if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
  1989. mutex_lock(&ioc->taskmgmt_cmds.mutex);
  1990. if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
  1991. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  1992. goto done_free_mem;
  1993. }
  1994. DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
  1995. if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
  1996. (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
  1997. mpt_put_msg_frame_hi_pri(mptctl_id, ioc, mf);
  1998. else {
  1999. rc =mpt_send_handshake_request(mptctl_id, ioc,
  2000. sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
  2001. if (rc != 0) {
  2002. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2003. "send_handshake FAILED! (ioc %p, mf %p)\n",
  2004. ioc->name, ioc, mf));
  2005. mpt_clear_taskmgmt_in_progress_flag(ioc);
  2006. rc = -ENODATA;
  2007. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  2008. goto done_free_mem;
  2009. }
  2010. }
  2011. } else
  2012. mpt_put_msg_frame(mptctl_id, ioc, mf);
  2013. /* Now wait for the command to complete */
  2014. timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT;
  2015. retry_wait:
  2016. timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
  2017. HZ*timeout);
  2018. if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  2019. rc = -ETIME;
  2020. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "%s: TIMED OUT!\n",
  2021. ioc->name, __func__));
  2022. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
  2023. if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
  2024. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  2025. goto done_free_mem;
  2026. }
  2027. if (!timeleft) {
  2028. printk(MYIOC_s_WARN_FMT
  2029. "mpt cmd timeout, doorbell=0x%08x"
  2030. " function=0x%x\n",
  2031. ioc->name, mpt_GetIocState(ioc, 0), function);
  2032. if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
  2033. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  2034. mptctl_timeout_expired(ioc, mf);
  2035. mf = NULL;
  2036. } else
  2037. goto retry_wait;
  2038. goto done_free_mem;
  2039. }
  2040. if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
  2041. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  2042. mf = NULL;
  2043. /* If a valid reply frame, copy to the user.
  2044. * Offset 2: reply length in U32's
  2045. */
  2046. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
  2047. if (karg.maxReplyBytes < ioc->reply_sz) {
  2048. sz = min(karg.maxReplyBytes,
  2049. 4*ioc->ioctl_cmds.reply[2]);
  2050. } else {
  2051. sz = min(ioc->reply_sz, 4*ioc->ioctl_cmds.reply[2]);
  2052. }
  2053. if (sz > 0) {
  2054. if (copy_to_user(karg.replyFrameBufPtr,
  2055. ioc->ioctl_cmds.reply, sz)){
  2056. printk(MYIOC_s_ERR_FMT
  2057. "%s@%d::mptctl_do_mpt_command - "
  2058. "Unable to write out reply frame %p\n",
  2059. ioc->name, __FILE__, __LINE__, karg.replyFrameBufPtr);
  2060. rc = -ENODATA;
  2061. goto done_free_mem;
  2062. }
  2063. }
  2064. }
  2065. /* If valid sense data, copy to user.
  2066. */
  2067. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_SENSE_VALID) {
  2068. sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
  2069. if (sz > 0) {
  2070. if (copy_to_user(karg.senseDataPtr,
  2071. ioc->ioctl_cmds.sense, sz)) {
  2072. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  2073. "Unable to write sense data to user %p\n",
  2074. ioc->name, __FILE__, __LINE__,
  2075. karg.senseDataPtr);
  2076. rc = -ENODATA;
  2077. goto done_free_mem;
  2078. }
  2079. }
  2080. }
  2081. /* If the overall status is _GOOD and data in, copy data
  2082. * to user.
  2083. */
  2084. if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD) &&
  2085. (karg.dataInSize > 0) && (bufIn.kptr)) {
  2086. if (copy_to_user(karg.dataInBufPtr,
  2087. bufIn.kptr, karg.dataInSize)) {
  2088. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
  2089. "Unable to write data to user %p\n",
  2090. ioc->name, __FILE__, __LINE__,
  2091. karg.dataInBufPtr);
  2092. rc = -ENODATA;
  2093. }
  2094. }
  2095. done_free_mem:
  2096. CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
  2097. SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
  2098. /* Free the allocated memory.
  2099. */
  2100. if (bufOut.kptr != NULL) {
  2101. pci_free_consistent(ioc->pcidev,
  2102. bufOut.len, (void *) bufOut.kptr, dma_addr_out);
  2103. }
  2104. if (bufIn.kptr != NULL) {
  2105. pci_free_consistent(ioc->pcidev,
  2106. bufIn.len, (void *) bufIn.kptr, dma_addr_in);
  2107. }
  2108. /* mf is null if command issued successfully
  2109. * otherwise, failure occurred after mf acquired.
  2110. */
  2111. if (mf)
  2112. mpt_free_msg_frame(ioc, mf);
  2113. return rc;
  2114. }
  2115. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2116. /* Prototype Routine for the HOST INFO command.
  2117. *
  2118. * Outputs: None.
  2119. * Return: 0 if successful
  2120. * -EFAULT if data unavailable
  2121. * -EBUSY if previous command timeout and IOC reset is not complete.
  2122. * -ENODEV if no such device/adapter
  2123. * -ETIME if timer expires
  2124. * -ENOMEM if memory allocation error
  2125. */
  2126. static int
  2127. mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
  2128. {
  2129. hp_host_info_t __user *uarg = (void __user *) arg;
  2130. MPT_ADAPTER *ioc;
  2131. struct pci_dev *pdev;
  2132. char *pbuf=NULL;
  2133. dma_addr_t buf_dma;
  2134. hp_host_info_t karg;
  2135. CONFIGPARMS cfg;
  2136. ConfigPageHeader_t hdr;
  2137. int iocnum;
  2138. int rc, cim_rev;
  2139. ToolboxIstwiReadWriteRequest_t *IstwiRWRequest;
  2140. MPT_FRAME_HDR *mf = NULL;
  2141. MPIHeader_t *mpi_hdr;
  2142. unsigned long timeleft;
  2143. int retval;
  2144. /* Reset long to int. Should affect IA64 and SPARC only
  2145. */
  2146. if (data_size == sizeof(hp_host_info_t))
  2147. cim_rev = 1;
  2148. else if (data_size == sizeof(hp_host_info_rev0_t))
  2149. cim_rev = 0; /* obsolete */
  2150. else
  2151. return -EFAULT;
  2152. if (copy_from_user(&karg, uarg, sizeof(hp_host_info_t))) {
  2153. printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_host_info - "
  2154. "Unable to read in hp_host_info struct @ %p\n",
  2155. __FILE__, __LINE__, uarg);
  2156. return -EFAULT;
  2157. }
  2158. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  2159. (ioc == NULL)) {
  2160. printk(KERN_DEBUG MYNAM "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
  2161. __FILE__, __LINE__, iocnum);
  2162. return -ENODEV;
  2163. }
  2164. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_hostinfo called.\n",
  2165. ioc->name));
  2166. /* Fill in the data and return the structure to the calling
  2167. * program
  2168. */
  2169. pdev = (struct pci_dev *) ioc->pcidev;
  2170. karg.vendor = pdev->vendor;
  2171. karg.device = pdev->device;
  2172. karg.subsystem_id = pdev->subsystem_device;
  2173. karg.subsystem_vendor = pdev->subsystem_vendor;
  2174. karg.devfn = pdev->devfn;
  2175. karg.bus = pdev->bus->number;
  2176. /* Save the SCSI host no. if
  2177. * SCSI driver loaded
  2178. */
  2179. if (ioc->sh != NULL)
  2180. karg.host_no = ioc->sh->host_no;
  2181. else
  2182. karg.host_no = -1;
  2183. /* Reformat the fw_version into a string
  2184. */
  2185. karg.fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ?
  2186. ((ioc->facts.FWVersion.Struct.Major / 10) + '0') : '0';
  2187. karg.fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) + '0';
  2188. karg.fw_version[2] = '.';
  2189. karg.fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ?
  2190. ((ioc->facts.FWVersion.Struct.Minor / 10) + '0') : '0';
  2191. karg.fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) + '0';
  2192. karg.fw_version[5] = '.';
  2193. karg.fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ?
  2194. ((ioc->facts.FWVersion.Struct.Unit / 10) + '0') : '0';
  2195. karg.fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) + '0';
  2196. karg.fw_version[8] = '.';
  2197. karg.fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ?
  2198. ((ioc->facts.FWVersion.Struct.Dev / 10) + '0') : '0';
  2199. karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0';
  2200. karg.fw_version[11] = '\0';
  2201. /* Issue a config request to get the device serial number
  2202. */
  2203. hdr.PageVersion = 0;
  2204. hdr.PageLength = 0;
  2205. hdr.PageNumber = 0;
  2206. hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
  2207. cfg.cfghdr.hdr = &hdr;
  2208. cfg.physAddr = -1;
  2209. cfg.pageAddr = 0;
  2210. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  2211. cfg.dir = 0; /* read */
  2212. cfg.timeout = 10;
  2213. strncpy(karg.serial_number, " ", 24);
  2214. if (mpt_config(ioc, &cfg) == 0) {
  2215. if (cfg.cfghdr.hdr->PageLength > 0) {
  2216. /* Issue the second config page request */
  2217. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  2218. pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
  2219. if (pbuf) {
  2220. cfg.physAddr = buf_dma;
  2221. if (mpt_config(ioc, &cfg) == 0) {
  2222. ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf;
  2223. if (strlen(pdata->BoardTracerNumber) > 1) {
  2224. strncpy(karg.serial_number, pdata->BoardTracerNumber, 24);
  2225. karg.serial_number[24-1]='\0';
  2226. }
  2227. }
  2228. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
  2229. pbuf = NULL;
  2230. }
  2231. }
  2232. }
  2233. rc = mpt_GetIocState(ioc, 1);
  2234. switch (rc) {
  2235. case MPI_IOC_STATE_OPERATIONAL:
  2236. karg.ioc_status = HP_STATUS_OK;
  2237. break;
  2238. case MPI_IOC_STATE_FAULT:
  2239. karg.ioc_status = HP_STATUS_FAILED;
  2240. break;
  2241. case MPI_IOC_STATE_RESET:
  2242. case MPI_IOC_STATE_READY:
  2243. default:
  2244. karg.ioc_status = HP_STATUS_OTHER;
  2245. break;
  2246. }
  2247. karg.base_io_addr = pci_resource_start(pdev, 0);
  2248. if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
  2249. karg.bus_phys_width = HP_BUS_WIDTH_UNK;
  2250. else
  2251. karg.bus_phys_width = HP_BUS_WIDTH_16;
  2252. karg.hard_resets = 0;
  2253. karg.soft_resets = 0;
  2254. karg.timeouts = 0;
  2255. if (ioc->sh != NULL) {
  2256. MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  2257. if (hd && (cim_rev == 1)) {
  2258. karg.hard_resets = ioc->hard_resets;
  2259. karg.soft_resets = ioc->soft_resets;
  2260. karg.timeouts = ioc->timeouts;
  2261. }
  2262. }
  2263. /*
  2264. * Gather ISTWI(Industry Standard Two Wire Interface) Data
  2265. */
  2266. if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
  2267. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
  2268. "%s, no msg frames!!\n", ioc->name, __func__));
  2269. goto out;
  2270. }
  2271. IstwiRWRequest = (ToolboxIstwiReadWriteRequest_t *)mf;
  2272. mpi_hdr = (MPIHeader_t *) mf;
  2273. memset(IstwiRWRequest,0,sizeof(ToolboxIstwiReadWriteRequest_t));
  2274. IstwiRWRequest->Function = MPI_FUNCTION_TOOLBOX;
  2275. IstwiRWRequest->Tool = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL;
  2276. IstwiRWRequest->MsgContext = mpi_hdr->MsgContext;
  2277. IstwiRWRequest->Flags = MPI_TB_ISTWI_FLAGS_READ;
  2278. IstwiRWRequest->NumAddressBytes = 0x01;
  2279. IstwiRWRequest->DataLength = cpu_to_le16(0x04);
  2280. if (pdev->devfn & 1)
  2281. IstwiRWRequest->DeviceAddr = 0xB2;
  2282. else
  2283. IstwiRWRequest->DeviceAddr = 0xB0;
  2284. pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
  2285. if (!pbuf)
  2286. goto out;
  2287. ioc->add_sge((char *)&IstwiRWRequest->SGL,
  2288. (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma);
  2289. retval = 0;
  2290. SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
  2291. IstwiRWRequest->MsgContext);
  2292. INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
  2293. mpt_put_msg_frame(mptctl_id, ioc, mf);
  2294. retry_wait:
  2295. timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
  2296. HZ*MPT_IOCTL_DEFAULT_TIMEOUT);
  2297. if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  2298. retval = -ETIME;
  2299. printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name, __func__);
  2300. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
  2301. mpt_free_msg_frame(ioc, mf);
  2302. goto out;
  2303. }
  2304. if (!timeleft) {
  2305. printk(MYIOC_s_WARN_FMT
  2306. "HOST INFO command timeout, doorbell=0x%08x\n",
  2307. ioc->name, mpt_GetIocState(ioc, 0));
  2308. mptctl_timeout_expired(ioc, mf);
  2309. } else
  2310. goto retry_wait;
  2311. goto out;
  2312. }
  2313. /*
  2314. *ISTWI Data Definition
  2315. * pbuf[0] = FW_VERSION = 0x4
  2316. * pbuf[1] = Bay Count = 6 or 4 or 2, depending on
  2317. * the config, you should be seeing one out of these three values
  2318. * pbuf[2] = Drive Installed Map = bit pattern depend on which
  2319. * bays have drives in them
  2320. * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3)
  2321. */
  2322. if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)
  2323. karg.rsvd = *(u32 *)pbuf;
  2324. out:
  2325. CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
  2326. SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
  2327. if (pbuf)
  2328. pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma);
  2329. /* Copy the data from kernel memory to user memory
  2330. */
  2331. if (copy_to_user((char __user *)arg, &karg, sizeof(hp_host_info_t))) {
  2332. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hpgethostinfo - "
  2333. "Unable to write out hp_host_info @ %p\n",
  2334. ioc->name, __FILE__, __LINE__, uarg);
  2335. return -EFAULT;
  2336. }
  2337. return 0;
  2338. }
  2339. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2340. /* Prototype Routine for the TARGET INFO command.
  2341. *
  2342. * Outputs: None.
  2343. * Return: 0 if successful
  2344. * -EFAULT if data unavailable
  2345. * -EBUSY if previous command timeout and IOC reset is not complete.
  2346. * -ENODEV if no such device/adapter
  2347. * -ETIME if timer expires
  2348. * -ENOMEM if memory allocation error
  2349. */
  2350. static int
  2351. mptctl_hp_targetinfo(unsigned long arg)
  2352. {
  2353. hp_target_info_t __user *uarg = (void __user *) arg;
  2354. SCSIDevicePage0_t *pg0_alloc;
  2355. SCSIDevicePage3_t *pg3_alloc;
  2356. MPT_ADAPTER *ioc;
  2357. MPT_SCSI_HOST *hd = NULL;
  2358. hp_target_info_t karg;
  2359. int iocnum;
  2360. int data_sz;
  2361. dma_addr_t page_dma;
  2362. CONFIGPARMS cfg;
  2363. ConfigPageHeader_t hdr;
  2364. int tmp, np, rc = 0;
  2365. if (copy_from_user(&karg, uarg, sizeof(hp_target_info_t))) {
  2366. printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_targetinfo - "
  2367. "Unable to read in hp_host_targetinfo struct @ %p\n",
  2368. __FILE__, __LINE__, uarg);
  2369. return -EFAULT;
  2370. }
  2371. if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
  2372. (ioc == NULL)) {
  2373. printk(KERN_DEBUG MYNAM "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
  2374. __FILE__, __LINE__, iocnum);
  2375. return -ENODEV;
  2376. }
  2377. dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_hp_targetinfo called.\n",
  2378. ioc->name));
  2379. /* There is nothing to do for FCP parts.
  2380. */
  2381. if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
  2382. return 0;
  2383. if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL))
  2384. return 0;
  2385. if (ioc->sh->host_no != karg.hdr.host)
  2386. return -ENODEV;
  2387. /* Get the data transfer speeds
  2388. */
  2389. data_sz = ioc->spi_data.sdp0length * 4;
  2390. pg0_alloc = (SCSIDevicePage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
  2391. if (pg0_alloc) {
  2392. hdr.PageVersion = ioc->spi_data.sdp0version;
  2393. hdr.PageLength = data_sz;
  2394. hdr.PageNumber = 0;
  2395. hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  2396. cfg.cfghdr.hdr = &hdr;
  2397. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  2398. cfg.dir = 0;
  2399. cfg.timeout = 0;
  2400. cfg.physAddr = page_dma;
  2401. cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
  2402. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  2403. np = le32_to_cpu(pg0_alloc->NegotiatedParameters);
  2404. karg.negotiated_width = np & MPI_SCSIDEVPAGE0_NP_WIDE ?
  2405. HP_BUS_WIDTH_16 : HP_BUS_WIDTH_8;
  2406. if (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) {
  2407. tmp = (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
  2408. if (tmp < 0x09)
  2409. karg.negotiated_speed = HP_DEV_SPEED_ULTRA320;
  2410. else if (tmp <= 0x09)
  2411. karg.negotiated_speed = HP_DEV_SPEED_ULTRA160;
  2412. else if (tmp <= 0x0A)
  2413. karg.negotiated_speed = HP_DEV_SPEED_ULTRA2;
  2414. else if (tmp <= 0x0C)
  2415. karg.negotiated_speed = HP_DEV_SPEED_ULTRA;
  2416. else if (tmp <= 0x25)
  2417. karg.negotiated_speed = HP_DEV_SPEED_FAST;
  2418. else
  2419. karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
  2420. } else
  2421. karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
  2422. }
  2423. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg0_alloc, page_dma);
  2424. }
  2425. /* Set defaults
  2426. */
  2427. karg.message_rejects = -1;
  2428. karg.phase_errors = -1;
  2429. karg.parity_errors = -1;
  2430. karg.select_timeouts = -1;
  2431. /* Get the target error parameters
  2432. */
  2433. hdr.PageVersion = 0;
  2434. hdr.PageLength = 0;
  2435. hdr.PageNumber = 3;
  2436. hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  2437. cfg.cfghdr.hdr = &hdr;
  2438. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  2439. cfg.dir = 0;
  2440. cfg.timeout = 0;
  2441. cfg.physAddr = -1;
  2442. if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) {
  2443. /* Issue the second config page request */
  2444. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  2445. data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
  2446. pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent(
  2447. ioc->pcidev, data_sz, &page_dma);
  2448. if (pg3_alloc) {
  2449. cfg.physAddr = page_dma;
  2450. cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
  2451. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  2452. karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount);
  2453. karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount);
  2454. karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount);
  2455. }
  2456. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg3_alloc, page_dma);
  2457. }
  2458. }
  2459. hd = shost_priv(ioc->sh);
  2460. if (hd != NULL)
  2461. karg.select_timeouts = hd->sel_timeout[karg.hdr.id];
  2462. /* Copy the data from kernel memory to user memory
  2463. */
  2464. if (copy_to_user((char __user *)arg, &karg, sizeof(hp_target_info_t))) {
  2465. printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hp_target_info - "
  2466. "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
  2467. ioc->name, __FILE__, __LINE__, uarg);
  2468. return -EFAULT;
  2469. }
  2470. return 0;
  2471. }
  2472. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2473. static const struct file_operations mptctl_fops = {
  2474. .owner = THIS_MODULE,
  2475. .llseek = no_llseek,
  2476. .fasync = mptctl_fasync,
  2477. .unlocked_ioctl = mptctl_ioctl,
  2478. .release = mptctl_release,
  2479. #ifdef CONFIG_COMPAT
  2480. .compat_ioctl = compat_mpctl_ioctl,
  2481. #endif
  2482. };
  2483. static struct miscdevice mptctl_miscdev = {
  2484. MPT_MINOR,
  2485. MYNAM,
  2486. &mptctl_fops
  2487. };
  2488. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2489. #ifdef CONFIG_COMPAT
  2490. static int
  2491. compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd,
  2492. unsigned long arg)
  2493. {
  2494. struct mpt_fw_xfer32 kfw32;
  2495. struct mpt_fw_xfer kfw;
  2496. MPT_ADAPTER *iocp = NULL;
  2497. int iocnum, iocnumX;
  2498. int nonblock = (filp->f_flags & O_NONBLOCK);
  2499. int ret;
  2500. if (copy_from_user(&kfw32, (char __user *)arg, sizeof(kfw32)))
  2501. return -EFAULT;
  2502. /* Verify intended MPT adapter */
  2503. iocnumX = kfw32.iocnum & 0xFF;
  2504. if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
  2505. (iocp == NULL)) {
  2506. printk(KERN_DEBUG MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
  2507. __LINE__, iocnumX);
  2508. return -ENODEV;
  2509. }
  2510. if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
  2511. return ret;
  2512. dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mptfwxfer_ioctl() called\n",
  2513. iocp->name));
  2514. kfw.iocnum = iocnum;
  2515. kfw.fwlen = kfw32.fwlen;
  2516. kfw.bufp = compat_ptr(kfw32.bufp);
  2517. ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen);
  2518. mutex_unlock(&iocp->ioctl_cmds.mutex);
  2519. return ret;
  2520. }
  2521. static int
  2522. compat_mpt_command(struct file *filp, unsigned int cmd,
  2523. unsigned long arg)
  2524. {
  2525. struct mpt_ioctl_command32 karg32;
  2526. struct mpt_ioctl_command32 __user *uarg = (struct mpt_ioctl_command32 __user *) arg;
  2527. struct mpt_ioctl_command karg;
  2528. MPT_ADAPTER *iocp = NULL;
  2529. int iocnum, iocnumX;
  2530. int nonblock = (filp->f_flags & O_NONBLOCK);
  2531. int ret;
  2532. if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32)))
  2533. return -EFAULT;
  2534. /* Verify intended MPT adapter */
  2535. iocnumX = karg32.hdr.iocnum & 0xFF;
  2536. if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
  2537. (iocp == NULL)) {
  2538. printk(KERN_DEBUG MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
  2539. __LINE__, iocnumX);
  2540. return -ENODEV;
  2541. }
  2542. if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
  2543. return ret;
  2544. dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mpt_command() called\n",
  2545. iocp->name));
  2546. /* Copy data to karg */
  2547. karg.hdr.iocnum = karg32.hdr.iocnum;
  2548. karg.hdr.port = karg32.hdr.port;
  2549. karg.timeout = karg32.timeout;
  2550. karg.maxReplyBytes = karg32.maxReplyBytes;
  2551. karg.dataInSize = karg32.dataInSize;
  2552. karg.dataOutSize = karg32.dataOutSize;
  2553. karg.maxSenseBytes = karg32.maxSenseBytes;
  2554. karg.dataSgeOffset = karg32.dataSgeOffset;
  2555. karg.replyFrameBufPtr = (char __user *)(unsigned long)karg32.replyFrameBufPtr;
  2556. karg.dataInBufPtr = (char __user *)(unsigned long)karg32.dataInBufPtr;
  2557. karg.dataOutBufPtr = (char __user *)(unsigned long)karg32.dataOutBufPtr;
  2558. karg.senseDataPtr = (char __user *)(unsigned long)karg32.senseDataPtr;
  2559. /* Pass new structure to do_mpt_command
  2560. */
  2561. ret = mptctl_do_mpt_command (karg, &uarg->MF);
  2562. mutex_unlock(&iocp->ioctl_cmds.mutex);
  2563. return ret;
  2564. }
  2565. static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
  2566. {
  2567. long ret;
  2568. mutex_lock(&mpctl_mutex);
  2569. switch (cmd) {
  2570. case MPTIOCINFO:
  2571. case MPTIOCINFO1:
  2572. case MPTIOCINFO2:
  2573. case MPTTARGETINFO:
  2574. case MPTEVENTQUERY:
  2575. case MPTEVENTENABLE:
  2576. case MPTEVENTREPORT:
  2577. case MPTHARDRESET:
  2578. case HP_GETHOSTINFO:
  2579. case HP_GETTARGETINFO:
  2580. case MPTTEST:
  2581. ret = __mptctl_ioctl(f, cmd, arg);
  2582. break;
  2583. case MPTCOMMAND32:
  2584. ret = compat_mpt_command(f, cmd, arg);
  2585. break;
  2586. case MPTFWDOWNLOAD32:
  2587. ret = compat_mptfwxfer_ioctl(f, cmd, arg);
  2588. break;
  2589. default:
  2590. ret = -ENOIOCTLCMD;
  2591. break;
  2592. }
  2593. mutex_unlock(&mpctl_mutex);
  2594. return ret;
  2595. }
  2596. #endif
  2597. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2598. /*
  2599. * mptctl_probe - Installs ioctl devices per bus.
  2600. * @pdev: Pointer to pci_dev structure
  2601. *
  2602. * Returns 0 for success, non-zero for failure.
  2603. *
  2604. */
  2605. static int
  2606. mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  2607. {
  2608. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  2609. mutex_init(&ioc->ioctl_cmds.mutex);
  2610. init_completion(&ioc->ioctl_cmds.done);
  2611. return 0;
  2612. }
  2613. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2614. /*
  2615. * mptctl_remove - Removed ioctl devices
  2616. * @pdev: Pointer to pci_dev structure
  2617. *
  2618. *
  2619. */
  2620. static void
  2621. mptctl_remove(struct pci_dev *pdev)
  2622. {
  2623. }
  2624. static struct mpt_pci_driver mptctl_driver = {
  2625. .probe = mptctl_probe,
  2626. .remove = mptctl_remove,
  2627. };
  2628. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2629. static int __init mptctl_init(void)
  2630. {
  2631. int err;
  2632. int where = 1;
  2633. show_mptmod_ver(my_NAME, my_VERSION);
  2634. mpt_device_driver_register(&mptctl_driver, MPTCTL_DRIVER);
  2635. /* Register this device */
  2636. err = misc_register(&mptctl_miscdev);
  2637. if (err < 0) {
  2638. printk(KERN_ERR MYNAM ": Can't register misc device [minor=%d].\n", MPT_MINOR);
  2639. goto out_fail;
  2640. }
  2641. printk(KERN_INFO MYNAM ": Registered with Fusion MPT base driver\n");
  2642. printk(KERN_INFO MYNAM ": /dev/%s @ (major,minor=%d,%d)\n",
  2643. mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
  2644. /*
  2645. * Install our handler
  2646. */
  2647. ++where;
  2648. mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER,
  2649. "mptctl_reply");
  2650. if (!mptctl_id || mptctl_id >= MPT_MAX_PROTOCOL_DRIVERS) {
  2651. printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
  2652. misc_deregister(&mptctl_miscdev);
  2653. err = -EBUSY;
  2654. goto out_fail;
  2655. }
  2656. mptctl_taskmgmt_id = mpt_register(mptctl_taskmgmt_reply, MPTCTL_DRIVER,
  2657. "mptctl_taskmgmt_reply");
  2658. if (!mptctl_taskmgmt_id || mptctl_taskmgmt_id >= MPT_MAX_PROTOCOL_DRIVERS) {
  2659. printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
  2660. mpt_deregister(mptctl_id);
  2661. misc_deregister(&mptctl_miscdev);
  2662. err = -EBUSY;
  2663. goto out_fail;
  2664. }
  2665. mpt_reset_register(mptctl_id, mptctl_ioc_reset);
  2666. mpt_event_register(mptctl_id, mptctl_event_process);
  2667. return 0;
  2668. out_fail:
  2669. mpt_device_driver_deregister(MPTCTL_DRIVER);
  2670. return err;
  2671. }
  2672. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2673. static void mptctl_exit(void)
  2674. {
  2675. misc_deregister(&mptctl_miscdev);
  2676. printk(KERN_INFO MYNAM ": Deregistered /dev/%s @ (major,minor=%d,%d)\n",
  2677. mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
  2678. /* De-register event handler from base module */
  2679. mpt_event_deregister(mptctl_id);
  2680. /* De-register reset handler from base module */
  2681. mpt_reset_deregister(mptctl_id);
  2682. /* De-register callback handler from base module */
  2683. mpt_deregister(mptctl_taskmgmt_id);
  2684. mpt_deregister(mptctl_id);
  2685. mpt_device_driver_deregister(MPTCTL_DRIVER);
  2686. }
  2687. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2688. module_init(mptctl_init);
  2689. module_exit(mptctl_exit);