mptspi.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  1. /*
  2. * linux/drivers/message/fusion/mptspi.c
  3. * For use with LSI PCI chip/adapter(s)
  4. * running LSI Fusion MPT (Message Passing Technology) firmware.
  5. *
  6. * Copyright (c) 1999-2008 LSI Corporation
  7. * (mailto:DL-MPTFusionLinux@lsi.com)
  8. *
  9. */
  10. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  11. /*
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; version 2 of the License.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. NO WARRANTY
  20. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  21. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  22. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  23. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  24. solely responsible for determining the appropriateness of using and
  25. distributing the Program and assumes all risks associated with its
  26. exercise of rights under this Agreement, including but not limited to
  27. the risks and costs of program errors, damage to or loss of data,
  28. programs or equipment, and unavailability or interruption of operations.
  29. DISCLAIMER OF LIABILITY
  30. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. You should have received a copy of the GNU General Public License
  38. along with this program; if not, write to the Free Software
  39. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  40. */
  41. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  42. #include <linux/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/slab.h>
  45. #include <linux/init.h>
  46. #include <linux/errno.h>
  47. #include <linux/kdev_t.h>
  48. #include <linux/blkdev.h>
  49. #include <linux/delay.h> /* for mdelay */
  50. #include <linux/interrupt.h> /* needed for in_interrupt() proto */
  51. #include <linux/reboot.h> /* notifier code */
  52. #include <linux/workqueue.h>
  53. #include <linux/raid_class.h>
  54. #include <scsi/scsi.h>
  55. #include <scsi/scsi_cmnd.h>
  56. #include <scsi/scsi_device.h>
  57. #include <scsi/scsi_host.h>
  58. #include <scsi/scsi_tcq.h>
  59. #include <scsi/scsi_transport.h>
  60. #include <scsi/scsi_transport_spi.h>
  61. #include <scsi/scsi_dbg.h>
  62. #include "mptbase.h"
  63. #include "mptscsih.h"
  64. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  65. #define my_NAME "Fusion MPT SPI Host driver"
  66. #define my_VERSION MPT_LINUX_VERSION_COMMON
  67. #define MYNAM "mptspi"
  68. MODULE_AUTHOR(MODULEAUTHOR);
  69. MODULE_DESCRIPTION(my_NAME);
  70. MODULE_LICENSE("GPL");
  71. MODULE_VERSION(my_VERSION);
  72. /* Command line args */
  73. static int mpt_saf_te = MPTSCSIH_SAF_TE;
  74. module_param(mpt_saf_te, int, 0);
  75. MODULE_PARM_DESC(mpt_saf_te, " Force enabling SEP Processor: enable=1 (default=MPTSCSIH_SAF_TE=0)");
  76. static void mptspi_write_offset(struct scsi_target *, int);
  77. static void mptspi_write_width(struct scsi_target *, int);
  78. static int mptspi_write_spi_device_pg1(struct scsi_target *,
  79. struct _CONFIG_PAGE_SCSI_DEVICE_1 *);
  80. static struct scsi_transport_template *mptspi_transport_template = NULL;
  81. static u8 mptspiDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
  82. static u8 mptspiTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
  83. static u8 mptspiInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
  84. /**
  85. * mptspi_setTargetNegoParms - Update the target negotiation parameters
  86. * @hd: Pointer to a SCSI Host Structure
  87. * @target: per target private data
  88. * @sdev: SCSI device
  89. *
  90. * Update the target negotiation parameters based on the the Inquiry
  91. * data, adapter capabilities, and NVRAM settings.
  92. **/
  93. static void
  94. mptspi_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *target,
  95. struct scsi_device *sdev)
  96. {
  97. MPT_ADAPTER *ioc = hd->ioc;
  98. SpiCfgData *pspi_data = &ioc->spi_data;
  99. int id = (int) target->id;
  100. int nvram;
  101. u8 width = MPT_NARROW;
  102. u8 factor = MPT_ASYNC;
  103. u8 offset = 0;
  104. u8 nfactor;
  105. u8 noQas = 1;
  106. target->negoFlags = pspi_data->noQas;
  107. if (sdev->scsi_level < SCSI_2) {
  108. width = 0;
  109. factor = MPT_ULTRA2;
  110. offset = pspi_data->maxSyncOffset;
  111. target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
  112. } else {
  113. if (scsi_device_wide(sdev))
  114. width = 1;
  115. if (scsi_device_sync(sdev)) {
  116. factor = pspi_data->minSyncFactor;
  117. if (!scsi_device_dt(sdev))
  118. factor = MPT_ULTRA2;
  119. else {
  120. if (!scsi_device_ius(sdev) &&
  121. !scsi_device_qas(sdev))
  122. factor = MPT_ULTRA160;
  123. else {
  124. factor = MPT_ULTRA320;
  125. if (scsi_device_qas(sdev)) {
  126. ddvprintk(ioc,
  127. printk(MYIOC_s_DEBUG_FMT "Enabling QAS due to "
  128. "byte56=%02x on id=%d!\n", ioc->name,
  129. scsi_device_qas(sdev), id));
  130. noQas = 0;
  131. }
  132. if (sdev->type == TYPE_TAPE &&
  133. scsi_device_ius(sdev))
  134. target->negoFlags |= MPT_TAPE_NEGO_IDP;
  135. }
  136. }
  137. offset = pspi_data->maxSyncOffset;
  138. /* If RAID, never disable QAS
  139. * else if non RAID, do not disable
  140. * QAS if bit 1 is set
  141. * bit 1 QAS support, non-raid only
  142. * bit 0 IU support
  143. */
  144. if (target->raidVolume == 1)
  145. noQas = 0;
  146. } else {
  147. factor = MPT_ASYNC;
  148. offset = 0;
  149. }
  150. }
  151. if (!sdev->tagged_supported)
  152. target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
  153. /* Update tflags based on NVRAM settings. (SCSI only)
  154. */
  155. if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  156. nvram = pspi_data->nvram[id];
  157. nfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8;
  158. if (width)
  159. width = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
  160. if (offset > 0) {
  161. /* Ensure factor is set to the
  162. * maximum of: adapter, nvram, inquiry
  163. */
  164. if (nfactor) {
  165. if (nfactor < pspi_data->minSyncFactor )
  166. nfactor = pspi_data->minSyncFactor;
  167. factor = max(factor, nfactor);
  168. if (factor == MPT_ASYNC)
  169. offset = 0;
  170. } else {
  171. offset = 0;
  172. factor = MPT_ASYNC;
  173. }
  174. } else {
  175. factor = MPT_ASYNC;
  176. }
  177. }
  178. /* Make sure data is consistent
  179. */
  180. if ((!width) && (factor < MPT_ULTRA2))
  181. factor = MPT_ULTRA2;
  182. /* Save the data to the target structure.
  183. */
  184. target->minSyncFactor = factor;
  185. target->maxOffset = offset;
  186. target->maxWidth = width;
  187. spi_min_period(scsi_target(sdev)) = factor;
  188. spi_max_offset(scsi_target(sdev)) = offset;
  189. spi_max_width(scsi_target(sdev)) = width;
  190. target->tflags |= MPT_TARGET_FLAGS_VALID_NEGO;
  191. /* Disable unused features.
  192. */
  193. if (!width)
  194. target->negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
  195. if (!offset)
  196. target->negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
  197. if ( factor > MPT_ULTRA320 )
  198. noQas = 0;
  199. if (noQas && (pspi_data->noQas == 0)) {
  200. pspi_data->noQas |= MPT_TARGET_NO_NEGO_QAS;
  201. target->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
  202. /* Disable QAS in a mixed configuration case
  203. */
  204. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  205. "Disabling QAS due to noQas=%02x on id=%d!\n", ioc->name, noQas, id));
  206. }
  207. }
  208. /**
  209. * mptspi_writeIOCPage4 - write IOC Page 4
  210. * @hd: Pointer to a SCSI Host Structure
  211. * @channel: channel number
  212. * @id: write IOC Page4 for this ID & Bus
  213. *
  214. * Return: -EAGAIN if unable to obtain a Message Frame
  215. * or 0 if success.
  216. *
  217. * Remark: We do not wait for a return, write pages sequentially.
  218. **/
  219. static int
  220. mptspi_writeIOCPage4(MPT_SCSI_HOST *hd, u8 channel , u8 id)
  221. {
  222. MPT_ADAPTER *ioc = hd->ioc;
  223. Config_t *pReq;
  224. IOCPage4_t *IOCPage4Ptr;
  225. MPT_FRAME_HDR *mf;
  226. dma_addr_t dataDma;
  227. u16 req_idx;
  228. u32 frameOffset;
  229. u32 flagsLength;
  230. int ii;
  231. /* Get a MF for this command.
  232. */
  233. if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
  234. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
  235. "writeIOCPage4 : no msg frames!\n",ioc->name));
  236. return -EAGAIN;
  237. }
  238. /* Set the request and the data pointers.
  239. * Place data at end of MF.
  240. */
  241. pReq = (Config_t *)mf;
  242. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  243. frameOffset = ioc->req_sz - sizeof(IOCPage4_t);
  244. /* Complete the request frame (same for all requests).
  245. */
  246. pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  247. pReq->Reserved = 0;
  248. pReq->ChainOffset = 0;
  249. pReq->Function = MPI_FUNCTION_CONFIG;
  250. pReq->ExtPageLength = 0;
  251. pReq->ExtPageType = 0;
  252. pReq->MsgFlags = 0;
  253. for (ii=0; ii < 8; ii++) {
  254. pReq->Reserved2[ii] = 0;
  255. }
  256. IOCPage4Ptr = ioc->spi_data.pIocPg4;
  257. dataDma = ioc->spi_data.IocPg4_dma;
  258. ii = IOCPage4Ptr->ActiveSEP++;
  259. IOCPage4Ptr->SEP[ii].SEPTargetID = id;
  260. IOCPage4Ptr->SEP[ii].SEPBus = channel;
  261. pReq->Header = IOCPage4Ptr->Header;
  262. pReq->PageAddress = cpu_to_le32(id | (channel << 8 ));
  263. /* Add a SGE to the config request.
  264. */
  265. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE |
  266. (IOCPage4Ptr->Header.PageLength + ii) * 4;
  267. ioc->add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
  268. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  269. "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n",
  270. ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, id, channel));
  271. mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
  272. return 0;
  273. }
  274. /**
  275. * mptspi_initTarget - Target, LUN alloc/free functionality.
  276. * @hd: Pointer to MPT_SCSI_HOST structure
  277. * @vtarget: per target private data
  278. * @sdev: SCSI device
  279. *
  280. * NOTE: It's only SAFE to call this routine if data points to
  281. * sane & valid STANDARD INQUIRY data!
  282. *
  283. * Allocate and initialize memory for this target.
  284. * Save inquiry data.
  285. *
  286. **/
  287. static void
  288. mptspi_initTarget(MPT_SCSI_HOST *hd, VirtTarget *vtarget,
  289. struct scsi_device *sdev)
  290. {
  291. /* Is LUN supported? If so, upper 2 bits will be 0
  292. * in first byte of inquiry data.
  293. */
  294. if (sdev->inq_periph_qual != 0)
  295. return;
  296. if (vtarget == NULL)
  297. return;
  298. vtarget->type = sdev->type;
  299. if ((sdev->type == TYPE_PROCESSOR) && (hd->ioc->spi_data.Saf_Te)) {
  300. /* Treat all Processors as SAF-TE if
  301. * command line option is set */
  302. vtarget->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
  303. mptspi_writeIOCPage4(hd, vtarget->channel, vtarget->id);
  304. }else if ((sdev->type == TYPE_PROCESSOR) &&
  305. !(vtarget->tflags & MPT_TARGET_FLAGS_SAF_TE_ISSUED )) {
  306. if (sdev->inquiry_len > 49 ) {
  307. if (sdev->inquiry[44] == 'S' &&
  308. sdev->inquiry[45] == 'A' &&
  309. sdev->inquiry[46] == 'F' &&
  310. sdev->inquiry[47] == '-' &&
  311. sdev->inquiry[48] == 'T' &&
  312. sdev->inquiry[49] == 'E' ) {
  313. vtarget->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
  314. mptspi_writeIOCPage4(hd, vtarget->channel, vtarget->id);
  315. }
  316. }
  317. }
  318. mptspi_setTargetNegoParms(hd, vtarget, sdev);
  319. }
  320. /**
  321. * mptspi_is_raid - Determines whether target is belonging to volume
  322. * @hd: Pointer to a SCSI HOST structure
  323. * @id: target device id
  324. *
  325. * Return:
  326. * non-zero = true
  327. * zero = false
  328. *
  329. */
  330. static int
  331. mptspi_is_raid(struct _MPT_SCSI_HOST *hd, u32 id)
  332. {
  333. int i, rc = 0;
  334. MPT_ADAPTER *ioc = hd->ioc;
  335. if (!ioc->raid_data.pIocPg2)
  336. goto out;
  337. if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
  338. goto out;
  339. for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
  340. if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id) {
  341. rc = 1;
  342. goto out;
  343. }
  344. }
  345. out:
  346. return rc;
  347. }
  348. static int mptspi_target_alloc(struct scsi_target *starget)
  349. {
  350. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  351. struct _MPT_SCSI_HOST *hd = shost_priv(shost);
  352. VirtTarget *vtarget;
  353. MPT_ADAPTER *ioc;
  354. if (hd == NULL)
  355. return -ENODEV;
  356. ioc = hd->ioc;
  357. vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
  358. if (!vtarget)
  359. return -ENOMEM;
  360. vtarget->ioc_id = ioc->id;
  361. vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
  362. vtarget->id = (u8)starget->id;
  363. vtarget->channel = (u8)starget->channel;
  364. vtarget->starget = starget;
  365. starget->hostdata = vtarget;
  366. if (starget->channel == 1) {
  367. if (mptscsih_is_phys_disk(ioc, 0, starget->id) == 0)
  368. return 0;
  369. vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
  370. /* The real channel for this device is zero */
  371. vtarget->channel = 0;
  372. /* The actual physdisknum (for RAID passthrough) */
  373. vtarget->id = mptscsih_raid_id_to_num(ioc, 0,
  374. starget->id);
  375. }
  376. if (starget->channel == 0 &&
  377. mptspi_is_raid(hd, starget->id)) {
  378. vtarget->raidVolume = 1;
  379. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  380. "RAID Volume @ channel=%d id=%d\n", ioc->name, starget->channel,
  381. starget->id));
  382. }
  383. if (ioc->spi_data.nvram &&
  384. ioc->spi_data.nvram[starget->id] != MPT_HOST_NVRAM_INVALID) {
  385. u32 nvram = ioc->spi_data.nvram[starget->id];
  386. spi_min_period(starget) = (nvram & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
  387. spi_max_width(starget) = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
  388. } else {
  389. spi_min_period(starget) = ioc->spi_data.minSyncFactor;
  390. spi_max_width(starget) = ioc->spi_data.maxBusWidth;
  391. }
  392. spi_max_offset(starget) = ioc->spi_data.maxSyncOffset;
  393. spi_offset(starget) = 0;
  394. spi_period(starget) = 0xFF;
  395. mptspi_write_width(starget, 0);
  396. return 0;
  397. }
  398. static void
  399. mptspi_target_destroy(struct scsi_target *starget)
  400. {
  401. kfree(starget->hostdata);
  402. starget->hostdata = NULL;
  403. }
  404. /**
  405. * mptspi_print_write_nego - negotiation parameters debug info that is being sent
  406. * @hd: Pointer to a SCSI HOST structure
  407. * @starget: SCSI target
  408. * @ii: negotiation parameters
  409. *
  410. */
  411. static void
  412. mptspi_print_write_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii)
  413. {
  414. ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d Requested = 0x%08x"
  415. " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n",
  416. hd->ioc->name, starget->id, ii,
  417. ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "",
  418. ((ii >> 8) & 0xFF), ((ii >> 16) & 0xFF),
  419. ii & MPI_SCSIDEVPAGE0_NP_IU ? "IU ": "",
  420. ii & MPI_SCSIDEVPAGE0_NP_DT ? "DT ": "",
  421. ii & MPI_SCSIDEVPAGE0_NP_QAS ? "QAS ": "",
  422. ii & MPI_SCSIDEVPAGE0_NP_HOLD_MCS ? "HOLDMCS ": "",
  423. ii & MPI_SCSIDEVPAGE0_NP_WR_FLOW ? "WRFLOW ": "",
  424. ii & MPI_SCSIDEVPAGE0_NP_RD_STRM ? "RDSTRM ": "",
  425. ii & MPI_SCSIDEVPAGE0_NP_RTI ? "RTI ": "",
  426. ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": ""));
  427. }
  428. /**
  429. * mptspi_print_read_nego - negotiation parameters debug info that is being read
  430. * @hd: Pointer to a SCSI HOST structure
  431. * @starget: SCSI target
  432. * @ii: negotiation parameters
  433. *
  434. */
  435. static void
  436. mptspi_print_read_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii)
  437. {
  438. ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d Read = 0x%08x"
  439. " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n",
  440. hd->ioc->name, starget->id, ii,
  441. ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "",
  442. ((ii >> 8) & 0xFF), ((ii >> 16) & 0xFF),
  443. ii & MPI_SCSIDEVPAGE0_NP_IU ? "IU ": "",
  444. ii & MPI_SCSIDEVPAGE0_NP_DT ? "DT ": "",
  445. ii & MPI_SCSIDEVPAGE0_NP_QAS ? "QAS ": "",
  446. ii & MPI_SCSIDEVPAGE0_NP_HOLD_MCS ? "HOLDMCS ": "",
  447. ii & MPI_SCSIDEVPAGE0_NP_WR_FLOW ? "WRFLOW ": "",
  448. ii & MPI_SCSIDEVPAGE0_NP_RD_STRM ? "RDSTRM ": "",
  449. ii & MPI_SCSIDEVPAGE0_NP_RTI ? "RTI ": "",
  450. ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": ""));
  451. }
  452. static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
  453. struct _CONFIG_PAGE_SCSI_DEVICE_0 *pass_pg0)
  454. {
  455. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  456. struct _MPT_SCSI_HOST *hd = shost_priv(shost);
  457. struct _MPT_ADAPTER *ioc = hd->ioc;
  458. struct _CONFIG_PAGE_SCSI_DEVICE_0 *spi_dev_pg0;
  459. dma_addr_t spi_dev_pg0_dma;
  460. int size;
  461. struct _x_config_parms cfg;
  462. struct _CONFIG_PAGE_HEADER hdr;
  463. int err = -EBUSY;
  464. /* No SPI parameters for RAID devices */
  465. if (starget->channel == 0 &&
  466. mptspi_is_raid(hd, starget->id))
  467. return -1;
  468. size = ioc->spi_data.sdp0length * 4;
  469. /*
  470. if (ioc->spi_data.sdp0length & 1)
  471. size += size + 4;
  472. size += 2048;
  473. */
  474. spi_dev_pg0 = dma_alloc_coherent(&ioc->pcidev->dev, size, &spi_dev_pg0_dma, GFP_KERNEL);
  475. if (spi_dev_pg0 == NULL) {
  476. starget_printk(KERN_ERR, starget, MYIOC_s_FMT
  477. "dma_alloc_coherent for parameters failed\n", ioc->name);
  478. return -EINVAL;
  479. }
  480. memset(&hdr, 0, sizeof(hdr));
  481. hdr.PageVersion = ioc->spi_data.sdp0version;
  482. hdr.PageLength = ioc->spi_data.sdp0length;
  483. hdr.PageNumber = 0;
  484. hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  485. memset(&cfg, 0, sizeof(cfg));
  486. cfg.cfghdr.hdr = &hdr;
  487. cfg.physAddr = spi_dev_pg0_dma;
  488. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  489. cfg.dir = 0;
  490. cfg.pageAddr = starget->id;
  491. cfg.timeout = 60;
  492. if (mpt_config(ioc, &cfg)) {
  493. starget_printk(KERN_ERR, starget, MYIOC_s_FMT "mpt_config failed\n", ioc->name);
  494. goto out_free;
  495. }
  496. err = 0;
  497. memcpy(pass_pg0, spi_dev_pg0, size);
  498. mptspi_print_read_nego(hd, starget, le32_to_cpu(spi_dev_pg0->NegotiatedParameters));
  499. out_free:
  500. dma_free_coherent(&ioc->pcidev->dev, size, spi_dev_pg0, spi_dev_pg0_dma);
  501. return err;
  502. }
  503. static u32 mptspi_getRP(struct scsi_target *starget)
  504. {
  505. u32 nego = 0;
  506. nego |= spi_iu(starget) ? MPI_SCSIDEVPAGE1_RP_IU : 0;
  507. nego |= spi_dt(starget) ? MPI_SCSIDEVPAGE1_RP_DT : 0;
  508. nego |= spi_qas(starget) ? MPI_SCSIDEVPAGE1_RP_QAS : 0;
  509. nego |= spi_hold_mcs(starget) ? MPI_SCSIDEVPAGE1_RP_HOLD_MCS : 0;
  510. nego |= spi_wr_flow(starget) ? MPI_SCSIDEVPAGE1_RP_WR_FLOW : 0;
  511. nego |= spi_rd_strm(starget) ? MPI_SCSIDEVPAGE1_RP_RD_STRM : 0;
  512. nego |= spi_rti(starget) ? MPI_SCSIDEVPAGE1_RP_RTI : 0;
  513. nego |= spi_pcomp_en(starget) ? MPI_SCSIDEVPAGE1_RP_PCOMP_EN : 0;
  514. nego |= (spi_period(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD) & MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK;
  515. nego |= (spi_offset(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MAX_SYNC_OFFSET) & MPI_SCSIDEVPAGE1_RP_MAX_SYNC_OFFSET_MASK;
  516. nego |= spi_width(starget) ? MPI_SCSIDEVPAGE1_RP_WIDE : 0;
  517. return nego;
  518. }
  519. static void mptspi_read_parameters(struct scsi_target *starget)
  520. {
  521. int nego;
  522. struct _CONFIG_PAGE_SCSI_DEVICE_0 spi_dev_pg0;
  523. mptspi_read_spi_device_pg0(starget, &spi_dev_pg0);
  524. nego = le32_to_cpu(spi_dev_pg0.NegotiatedParameters);
  525. spi_iu(starget) = (nego & MPI_SCSIDEVPAGE0_NP_IU) ? 1 : 0;
  526. spi_dt(starget) = (nego & MPI_SCSIDEVPAGE0_NP_DT) ? 1 : 0;
  527. spi_qas(starget) = (nego & MPI_SCSIDEVPAGE0_NP_QAS) ? 1 : 0;
  528. spi_wr_flow(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WR_FLOW) ? 1 : 0;
  529. spi_rd_strm(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RD_STRM) ? 1 : 0;
  530. spi_rti(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RTI) ? 1 : 0;
  531. spi_pcomp_en(starget) = (nego & MPI_SCSIDEVPAGE0_NP_PCOMP_EN) ? 1 : 0;
  532. spi_hold_mcs(starget) = (nego & MPI_SCSIDEVPAGE0_NP_HOLD_MCS) ? 1 : 0;
  533. spi_period(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_PERIOD;
  534. spi_offset(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_OFFSET;
  535. spi_width(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WIDE) ? 1 : 0;
  536. }
  537. static int
  538. mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id)
  539. {
  540. MPT_ADAPTER *ioc = hd->ioc;
  541. MpiRaidActionRequest_t *pReq;
  542. MPT_FRAME_HDR *mf;
  543. int ret;
  544. unsigned long timeleft;
  545. mutex_lock(&ioc->internal_cmds.mutex);
  546. /* Get and Populate a free Frame
  547. */
  548. if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
  549. dfailprintk(hd->ioc, printk(MYIOC_s_WARN_FMT
  550. "%s: no msg frames!\n", ioc->name, __func__));
  551. ret = -EAGAIN;
  552. goto out;
  553. }
  554. pReq = (MpiRaidActionRequest_t *)mf;
  555. if (quiesce)
  556. pReq->Action = MPI_RAID_ACTION_QUIESCE_PHYS_IO;
  557. else
  558. pReq->Action = MPI_RAID_ACTION_ENABLE_PHYS_IO;
  559. pReq->Reserved1 = 0;
  560. pReq->ChainOffset = 0;
  561. pReq->Function = MPI_FUNCTION_RAID_ACTION;
  562. pReq->VolumeID = id;
  563. pReq->VolumeBus = channel;
  564. pReq->PhysDiskNum = 0;
  565. pReq->MsgFlags = 0;
  566. pReq->Reserved2 = 0;
  567. pReq->ActionDataWord = 0; /* Reserved for this action */
  568. ioc->add_sge((char *)&pReq->ActionDataSGE,
  569. MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
  570. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RAID Volume action=%x channel=%d id=%d\n",
  571. ioc->name, pReq->Action, channel, id));
  572. INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)
  573. mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
  574. timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done, 10*HZ);
  575. if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  576. ret = -ETIME;
  577. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: TIMED OUT!\n",
  578. ioc->name, __func__));
  579. if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
  580. goto out;
  581. if (!timeleft) {
  582. printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
  583. ioc->name, __func__);
  584. mpt_HardResetHandler(ioc, CAN_SLEEP);
  585. mpt_free_msg_frame(ioc, mf);
  586. }
  587. goto out;
  588. }
  589. ret = ioc->internal_cmds.completion_code;
  590. out:
  591. CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
  592. mutex_unlock(&ioc->internal_cmds.mutex);
  593. return ret;
  594. }
  595. static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
  596. struct scsi_device *sdev)
  597. {
  598. VirtTarget *vtarget = scsi_target(sdev)->hostdata;
  599. MPT_ADAPTER *ioc = hd->ioc;
  600. /* no DV on RAID devices */
  601. if (sdev->channel == 0 &&
  602. mptspi_is_raid(hd, sdev->id))
  603. return;
  604. /* If this is a piece of a RAID, then quiesce first */
  605. if (sdev->channel == 1 &&
  606. mptscsih_quiesce_raid(hd, 1, vtarget->channel, vtarget->id) < 0) {
  607. starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT
  608. "Integrated RAID quiesce failed\n", ioc->name);
  609. return;
  610. }
  611. hd->spi_pending |= (1 << sdev->id);
  612. spi_dv_device(sdev);
  613. hd->spi_pending &= ~(1 << sdev->id);
  614. if (sdev->channel == 1 &&
  615. mptscsih_quiesce_raid(hd, 0, vtarget->channel, vtarget->id) < 0)
  616. starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT
  617. "Integrated RAID resume failed\n", ioc->name);
  618. mptspi_read_parameters(sdev->sdev_target);
  619. spi_display_xfer_agreement(sdev->sdev_target);
  620. mptspi_read_parameters(sdev->sdev_target);
  621. }
  622. static int mptspi_slave_alloc(struct scsi_device *sdev)
  623. {
  624. MPT_SCSI_HOST *hd = shost_priv(sdev->host);
  625. VirtTarget *vtarget;
  626. VirtDevice *vdevice;
  627. struct scsi_target *starget;
  628. MPT_ADAPTER *ioc = hd->ioc;
  629. if (sdev->channel == 1 &&
  630. mptscsih_is_phys_disk(ioc, 0, sdev->id) == 0)
  631. return -ENXIO;
  632. vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
  633. if (!vdevice) {
  634. printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
  635. ioc->name, sizeof(VirtDevice));
  636. return -ENOMEM;
  637. }
  638. vdevice->lun = sdev->lun;
  639. sdev->hostdata = vdevice;
  640. starget = scsi_target(sdev);
  641. vtarget = starget->hostdata;
  642. vdevice->vtarget = vtarget;
  643. vtarget->num_luns++;
  644. if (sdev->channel == 1)
  645. sdev->no_uld_attach = 1;
  646. return 0;
  647. }
  648. static int mptspi_slave_configure(struct scsi_device *sdev)
  649. {
  650. struct _MPT_SCSI_HOST *hd = shost_priv(sdev->host);
  651. VirtTarget *vtarget = scsi_target(sdev)->hostdata;
  652. int ret;
  653. mptspi_initTarget(hd, vtarget, sdev);
  654. ret = mptscsih_slave_configure(sdev);
  655. if (ret)
  656. return ret;
  657. ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d min_period=0x%02x"
  658. " max_offset=0x%02x max_width=%d\n", hd->ioc->name,
  659. sdev->id, spi_min_period(scsi_target(sdev)),
  660. spi_max_offset(scsi_target(sdev)),
  661. spi_max_width(scsi_target(sdev))));
  662. if ((sdev->channel == 1 ||
  663. !(mptspi_is_raid(hd, sdev->id))) &&
  664. !spi_initial_dv(sdev->sdev_target))
  665. mptspi_dv_device(hd, sdev);
  666. return 0;
  667. }
  668. static int
  669. mptspi_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt)
  670. {
  671. struct _MPT_SCSI_HOST *hd = shost_priv(shost);
  672. VirtDevice *vdevice = SCpnt->device->hostdata;
  673. MPT_ADAPTER *ioc = hd->ioc;
  674. if (!vdevice || !vdevice->vtarget) {
  675. SCpnt->result = DID_NO_CONNECT << 16;
  676. SCpnt->scsi_done(SCpnt);
  677. return 0;
  678. }
  679. if (SCpnt->device->channel == 1 &&
  680. mptscsih_is_phys_disk(ioc, 0, SCpnt->device->id) == 0) {
  681. SCpnt->result = DID_NO_CONNECT << 16;
  682. SCpnt->scsi_done(SCpnt);
  683. return 0;
  684. }
  685. if (spi_dv_pending(scsi_target(SCpnt->device)))
  686. ddvprintk(ioc, scsi_print_command(SCpnt));
  687. return mptscsih_qcmd(SCpnt);
  688. }
  689. static void mptspi_slave_destroy(struct scsi_device *sdev)
  690. {
  691. struct scsi_target *starget = scsi_target(sdev);
  692. VirtTarget *vtarget = starget->hostdata;
  693. VirtDevice *vdevice = sdev->hostdata;
  694. /* Will this be the last lun on a non-raid device? */
  695. if (vtarget->num_luns == 1 && vdevice->configured_lun) {
  696. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  697. /* Async Narrow */
  698. pg1.RequestedParameters = 0;
  699. pg1.Reserved = 0;
  700. pg1.Configuration = 0;
  701. mptspi_write_spi_device_pg1(starget, &pg1);
  702. }
  703. mptscsih_slave_destroy(sdev);
  704. }
  705. static struct scsi_host_template mptspi_driver_template = {
  706. .module = THIS_MODULE,
  707. .proc_name = "mptspi",
  708. .show_info = mptscsih_show_info,
  709. .name = "MPT SPI Host",
  710. .info = mptscsih_info,
  711. .queuecommand = mptspi_qcmd,
  712. .target_alloc = mptspi_target_alloc,
  713. .slave_alloc = mptspi_slave_alloc,
  714. .slave_configure = mptspi_slave_configure,
  715. .target_destroy = mptspi_target_destroy,
  716. .slave_destroy = mptspi_slave_destroy,
  717. .change_queue_depth = mptscsih_change_queue_depth,
  718. .eh_abort_handler = mptscsih_abort,
  719. .eh_device_reset_handler = mptscsih_dev_reset,
  720. .eh_bus_reset_handler = mptscsih_bus_reset,
  721. .eh_host_reset_handler = mptscsih_host_reset,
  722. .bios_param = mptscsih_bios_param,
  723. .can_queue = MPT_SCSI_CAN_QUEUE,
  724. .this_id = -1,
  725. .sg_tablesize = MPT_SCSI_SG_DEPTH,
  726. .max_sectors = 8192,
  727. .cmd_per_lun = 7,
  728. .use_clustering = ENABLE_CLUSTERING,
  729. .shost_attrs = mptscsih_host_attrs,
  730. };
  731. static int mptspi_write_spi_device_pg1(struct scsi_target *starget,
  732. struct _CONFIG_PAGE_SCSI_DEVICE_1 *pass_pg1)
  733. {
  734. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  735. struct _MPT_SCSI_HOST *hd = shost_priv(shost);
  736. struct _MPT_ADAPTER *ioc = hd->ioc;
  737. struct _CONFIG_PAGE_SCSI_DEVICE_1 *pg1;
  738. dma_addr_t pg1_dma;
  739. int size;
  740. struct _x_config_parms cfg;
  741. struct _CONFIG_PAGE_HEADER hdr;
  742. int err = -EBUSY;
  743. u32 nego_parms;
  744. u32 period;
  745. struct scsi_device *sdev;
  746. int i;
  747. /* don't allow updating nego parameters on RAID devices */
  748. if (starget->channel == 0 &&
  749. mptspi_is_raid(hd, starget->id))
  750. return -1;
  751. size = ioc->spi_data.sdp1length * 4;
  752. pg1 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg1_dma, GFP_KERNEL);
  753. if (pg1 == NULL) {
  754. starget_printk(KERN_ERR, starget, MYIOC_s_FMT
  755. "dma_alloc_coherent for parameters failed\n", ioc->name);
  756. return -EINVAL;
  757. }
  758. memset(&hdr, 0, sizeof(hdr));
  759. hdr.PageVersion = ioc->spi_data.sdp1version;
  760. hdr.PageLength = ioc->spi_data.sdp1length;
  761. hdr.PageNumber = 1;
  762. hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  763. memset(&cfg, 0, sizeof(cfg));
  764. cfg.cfghdr.hdr = &hdr;
  765. cfg.physAddr = pg1_dma;
  766. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  767. cfg.dir = 1;
  768. cfg.pageAddr = starget->id;
  769. memcpy(pg1, pass_pg1, size);
  770. pg1->Header.PageVersion = hdr.PageVersion;
  771. pg1->Header.PageLength = hdr.PageLength;
  772. pg1->Header.PageNumber = hdr.PageNumber;
  773. pg1->Header.PageType = hdr.PageType;
  774. nego_parms = le32_to_cpu(pg1->RequestedParameters);
  775. period = (nego_parms & MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK) >>
  776. MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD;
  777. if (period == 8) {
  778. /* Turn on inline data padding for TAPE when running U320 */
  779. for (i = 0 ; i < 16; i++) {
  780. sdev = scsi_device_lookup_by_target(starget, i);
  781. if (sdev && sdev->type == TYPE_TAPE) {
  782. sdev_printk(KERN_DEBUG, sdev, MYIOC_s_FMT
  783. "IDP:ON\n", ioc->name);
  784. nego_parms |= MPI_SCSIDEVPAGE1_RP_IDP;
  785. pg1->RequestedParameters =
  786. cpu_to_le32(nego_parms);
  787. break;
  788. }
  789. }
  790. }
  791. mptspi_print_write_nego(hd, starget, le32_to_cpu(pg1->RequestedParameters));
  792. if (mpt_config(ioc, &cfg)) {
  793. starget_printk(KERN_ERR, starget, MYIOC_s_FMT
  794. "mpt_config failed\n", ioc->name);
  795. goto out_free;
  796. }
  797. err = 0;
  798. out_free:
  799. dma_free_coherent(&ioc->pcidev->dev, size, pg1, pg1_dma);
  800. return err;
  801. }
  802. static void mptspi_write_offset(struct scsi_target *starget, int offset)
  803. {
  804. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  805. u32 nego;
  806. if (offset < 0)
  807. offset = 0;
  808. if (offset > 255)
  809. offset = 255;
  810. if (spi_offset(starget) == -1)
  811. mptspi_read_parameters(starget);
  812. spi_offset(starget) = offset;
  813. nego = mptspi_getRP(starget);
  814. pg1.RequestedParameters = cpu_to_le32(nego);
  815. pg1.Reserved = 0;
  816. pg1.Configuration = 0;
  817. mptspi_write_spi_device_pg1(starget, &pg1);
  818. }
  819. static void mptspi_write_period(struct scsi_target *starget, int period)
  820. {
  821. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  822. u32 nego;
  823. if (period < 8)
  824. period = 8;
  825. if (period > 255)
  826. period = 255;
  827. if (spi_period(starget) == -1)
  828. mptspi_read_parameters(starget);
  829. if (period == 8) {
  830. spi_iu(starget) = 1;
  831. spi_dt(starget) = 1;
  832. } else if (period == 9) {
  833. spi_dt(starget) = 1;
  834. }
  835. spi_period(starget) = period;
  836. nego = mptspi_getRP(starget);
  837. pg1.RequestedParameters = cpu_to_le32(nego);
  838. pg1.Reserved = 0;
  839. pg1.Configuration = 0;
  840. mptspi_write_spi_device_pg1(starget, &pg1);
  841. }
  842. static void mptspi_write_dt(struct scsi_target *starget, int dt)
  843. {
  844. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  845. u32 nego;
  846. if (spi_period(starget) == -1)
  847. mptspi_read_parameters(starget);
  848. if (!dt && spi_period(starget) < 10)
  849. spi_period(starget) = 10;
  850. spi_dt(starget) = dt;
  851. nego = mptspi_getRP(starget);
  852. pg1.RequestedParameters = cpu_to_le32(nego);
  853. pg1.Reserved = 0;
  854. pg1.Configuration = 0;
  855. mptspi_write_spi_device_pg1(starget, &pg1);
  856. }
  857. static void mptspi_write_iu(struct scsi_target *starget, int iu)
  858. {
  859. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  860. u32 nego;
  861. if (spi_period(starget) == -1)
  862. mptspi_read_parameters(starget);
  863. if (!iu && spi_period(starget) < 9)
  864. spi_period(starget) = 9;
  865. spi_iu(starget) = iu;
  866. nego = mptspi_getRP(starget);
  867. pg1.RequestedParameters = cpu_to_le32(nego);
  868. pg1.Reserved = 0;
  869. pg1.Configuration = 0;
  870. mptspi_write_spi_device_pg1(starget, &pg1);
  871. }
  872. #define MPTSPI_SIMPLE_TRANSPORT_PARM(parm) \
  873. static void mptspi_write_##parm(struct scsi_target *starget, int parm)\
  874. { \
  875. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; \
  876. u32 nego; \
  877. \
  878. spi_##parm(starget) = parm; \
  879. \
  880. nego = mptspi_getRP(starget); \
  881. \
  882. pg1.RequestedParameters = cpu_to_le32(nego); \
  883. pg1.Reserved = 0; \
  884. pg1.Configuration = 0; \
  885. \
  886. mptspi_write_spi_device_pg1(starget, &pg1); \
  887. }
  888. MPTSPI_SIMPLE_TRANSPORT_PARM(rd_strm)
  889. MPTSPI_SIMPLE_TRANSPORT_PARM(wr_flow)
  890. MPTSPI_SIMPLE_TRANSPORT_PARM(rti)
  891. MPTSPI_SIMPLE_TRANSPORT_PARM(hold_mcs)
  892. MPTSPI_SIMPLE_TRANSPORT_PARM(pcomp_en)
  893. static void mptspi_write_qas(struct scsi_target *starget, int qas)
  894. {
  895. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  896. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  897. struct _MPT_SCSI_HOST *hd = shost_priv(shost);
  898. VirtTarget *vtarget = starget->hostdata;
  899. u32 nego;
  900. if ((vtarget->negoFlags & MPT_TARGET_NO_NEGO_QAS) ||
  901. hd->ioc->spi_data.noQas)
  902. spi_qas(starget) = 0;
  903. else
  904. spi_qas(starget) = qas;
  905. nego = mptspi_getRP(starget);
  906. pg1.RequestedParameters = cpu_to_le32(nego);
  907. pg1.Reserved = 0;
  908. pg1.Configuration = 0;
  909. mptspi_write_spi_device_pg1(starget, &pg1);
  910. }
  911. static void mptspi_write_width(struct scsi_target *starget, int width)
  912. {
  913. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  914. u32 nego;
  915. if (!width) {
  916. spi_dt(starget) = 0;
  917. if (spi_period(starget) < 10)
  918. spi_period(starget) = 10;
  919. }
  920. spi_width(starget) = width;
  921. nego = mptspi_getRP(starget);
  922. pg1.RequestedParameters = cpu_to_le32(nego);
  923. pg1.Reserved = 0;
  924. pg1.Configuration = 0;
  925. mptspi_write_spi_device_pg1(starget, &pg1);
  926. }
  927. struct work_queue_wrapper {
  928. struct work_struct work;
  929. struct _MPT_SCSI_HOST *hd;
  930. int disk;
  931. };
  932. static void mpt_work_wrapper(struct work_struct *work)
  933. {
  934. struct work_queue_wrapper *wqw =
  935. container_of(work, struct work_queue_wrapper, work);
  936. struct _MPT_SCSI_HOST *hd = wqw->hd;
  937. MPT_ADAPTER *ioc = hd->ioc;
  938. struct Scsi_Host *shost = ioc->sh;
  939. struct scsi_device *sdev;
  940. int disk = wqw->disk;
  941. struct _CONFIG_PAGE_IOC_3 *pg3;
  942. kfree(wqw);
  943. mpt_findImVolumes(ioc);
  944. pg3 = ioc->raid_data.pIocPg3;
  945. if (!pg3)
  946. return;
  947. shost_for_each_device(sdev,shost) {
  948. struct scsi_target *starget = scsi_target(sdev);
  949. VirtTarget *vtarget = starget->hostdata;
  950. /* only want to search RAID components */
  951. if (sdev->channel != 1)
  952. continue;
  953. /* The id is the raid PhysDiskNum, even if
  954. * starget->id is the actual target address */
  955. if(vtarget->id != disk)
  956. continue;
  957. starget_printk(KERN_INFO, vtarget->starget, MYIOC_s_FMT
  958. "Integrated RAID requests DV of new device\n", ioc->name);
  959. mptspi_dv_device(hd, sdev);
  960. }
  961. shost_printk(KERN_INFO, shost, MYIOC_s_FMT
  962. "Integrated RAID detects new device %d\n", ioc->name, disk);
  963. scsi_scan_target(&ioc->sh->shost_gendev, 1, disk, 0, SCSI_SCAN_RESCAN);
  964. }
  965. static void mpt_dv_raid(struct _MPT_SCSI_HOST *hd, int disk)
  966. {
  967. struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC);
  968. MPT_ADAPTER *ioc = hd->ioc;
  969. if (!wqw) {
  970. shost_printk(KERN_ERR, ioc->sh, MYIOC_s_FMT
  971. "Failed to act on RAID event for physical disk %d\n",
  972. ioc->name, disk);
  973. return;
  974. }
  975. INIT_WORK(&wqw->work, mpt_work_wrapper);
  976. wqw->hd = hd;
  977. wqw->disk = disk;
  978. schedule_work(&wqw->work);
  979. }
  980. static int
  981. mptspi_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
  982. {
  983. u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
  984. struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  985. if (ioc->bus_type != SPI)
  986. return 0;
  987. if (hd && event == MPI_EVENT_INTEGRATED_RAID) {
  988. int reason
  989. = (le32_to_cpu(pEvReply->Data[0]) & 0x00FF0000) >> 16;
  990. if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
  991. int disk = (le32_to_cpu(pEvReply->Data[0]) & 0xFF000000) >> 24;
  992. mpt_dv_raid(hd, disk);
  993. }
  994. }
  995. return mptscsih_event_process(ioc, pEvReply);
  996. }
  997. static int
  998. mptspi_deny_binding(struct scsi_target *starget)
  999. {
  1000. struct _MPT_SCSI_HOST *hd =
  1001. (struct _MPT_SCSI_HOST *)dev_to_shost(starget->dev.parent)->hostdata;
  1002. return ((mptspi_is_raid(hd, starget->id)) &&
  1003. starget->channel == 0) ? 1 : 0;
  1004. }
  1005. static struct spi_function_template mptspi_transport_functions = {
  1006. .get_offset = mptspi_read_parameters,
  1007. .set_offset = mptspi_write_offset,
  1008. .show_offset = 1,
  1009. .get_period = mptspi_read_parameters,
  1010. .set_period = mptspi_write_period,
  1011. .show_period = 1,
  1012. .get_width = mptspi_read_parameters,
  1013. .set_width = mptspi_write_width,
  1014. .show_width = 1,
  1015. .get_iu = mptspi_read_parameters,
  1016. .set_iu = mptspi_write_iu,
  1017. .show_iu = 1,
  1018. .get_dt = mptspi_read_parameters,
  1019. .set_dt = mptspi_write_dt,
  1020. .show_dt = 1,
  1021. .get_qas = mptspi_read_parameters,
  1022. .set_qas = mptspi_write_qas,
  1023. .show_qas = 1,
  1024. .get_wr_flow = mptspi_read_parameters,
  1025. .set_wr_flow = mptspi_write_wr_flow,
  1026. .show_wr_flow = 1,
  1027. .get_rd_strm = mptspi_read_parameters,
  1028. .set_rd_strm = mptspi_write_rd_strm,
  1029. .show_rd_strm = 1,
  1030. .get_rti = mptspi_read_parameters,
  1031. .set_rti = mptspi_write_rti,
  1032. .show_rti = 1,
  1033. .get_pcomp_en = mptspi_read_parameters,
  1034. .set_pcomp_en = mptspi_write_pcomp_en,
  1035. .show_pcomp_en = 1,
  1036. .get_hold_mcs = mptspi_read_parameters,
  1037. .set_hold_mcs = mptspi_write_hold_mcs,
  1038. .show_hold_mcs = 1,
  1039. .deny_binding = mptspi_deny_binding,
  1040. };
  1041. /****************************************************************************
  1042. * Supported hardware
  1043. */
  1044. static struct pci_device_id mptspi_pci_table[] = {
  1045. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1030,
  1046. PCI_ANY_ID, PCI_ANY_ID },
  1047. { PCI_VENDOR_ID_ATTO, MPI_MANUFACTPAGE_DEVID_53C1030,
  1048. PCI_ANY_ID, PCI_ANY_ID },
  1049. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1035,
  1050. PCI_ANY_ID, PCI_ANY_ID },
  1051. {0} /* Terminating entry */
  1052. };
  1053. MODULE_DEVICE_TABLE(pci, mptspi_pci_table);
  1054. /*
  1055. * renegotiate for a given target
  1056. */
  1057. static void
  1058. mptspi_dv_renegotiate_work(struct work_struct *work)
  1059. {
  1060. struct work_queue_wrapper *wqw =
  1061. container_of(work, struct work_queue_wrapper, work);
  1062. struct _MPT_SCSI_HOST *hd = wqw->hd;
  1063. struct scsi_device *sdev;
  1064. struct scsi_target *starget;
  1065. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  1066. u32 nego;
  1067. MPT_ADAPTER *ioc = hd->ioc;
  1068. kfree(wqw);
  1069. if (hd->spi_pending) {
  1070. shost_for_each_device(sdev, ioc->sh) {
  1071. if (hd->spi_pending & (1 << sdev->id))
  1072. continue;
  1073. starget = scsi_target(sdev);
  1074. nego = mptspi_getRP(starget);
  1075. pg1.RequestedParameters = cpu_to_le32(nego);
  1076. pg1.Reserved = 0;
  1077. pg1.Configuration = 0;
  1078. mptspi_write_spi_device_pg1(starget, &pg1);
  1079. }
  1080. } else {
  1081. shost_for_each_device(sdev, ioc->sh)
  1082. mptspi_dv_device(hd, sdev);
  1083. }
  1084. }
  1085. static void
  1086. mptspi_dv_renegotiate(struct _MPT_SCSI_HOST *hd)
  1087. {
  1088. struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC);
  1089. if (!wqw)
  1090. return;
  1091. INIT_WORK(&wqw->work, mptspi_dv_renegotiate_work);
  1092. wqw->hd = hd;
  1093. schedule_work(&wqw->work);
  1094. }
  1095. /*
  1096. * spi module reset handler
  1097. */
  1098. static int
  1099. mptspi_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  1100. {
  1101. int rc;
  1102. rc = mptscsih_ioc_reset(ioc, reset_phase);
  1103. if ((ioc->bus_type != SPI) || (!rc))
  1104. return rc;
  1105. /* only try to do a renegotiation if we're properly set up
  1106. * if we get an ioc fault on bringup, ioc->sh will be NULL */
  1107. if (reset_phase == MPT_IOC_POST_RESET &&
  1108. ioc->sh) {
  1109. struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  1110. mptspi_dv_renegotiate(hd);
  1111. }
  1112. return rc;
  1113. }
  1114. #ifdef CONFIG_PM
  1115. /*
  1116. * spi module resume handler
  1117. */
  1118. static int
  1119. mptspi_resume(struct pci_dev *pdev)
  1120. {
  1121. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1122. struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  1123. int rc;
  1124. rc = mptscsih_resume(pdev);
  1125. mptspi_dv_renegotiate(hd);
  1126. return rc;
  1127. }
  1128. #endif
  1129. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1130. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1131. /*
  1132. * mptspi_probe - Installs scsi devices per bus.
  1133. * @pdev: Pointer to pci_dev structure
  1134. *
  1135. * Returns 0 for success, non-zero for failure.
  1136. *
  1137. */
  1138. static int
  1139. mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1140. {
  1141. struct Scsi_Host *sh;
  1142. MPT_SCSI_HOST *hd;
  1143. MPT_ADAPTER *ioc;
  1144. unsigned long flags;
  1145. int ii;
  1146. int numSGE = 0;
  1147. int scale;
  1148. int ioc_cap;
  1149. int error=0;
  1150. int r;
  1151. if ((r = mpt_attach(pdev,id)) != 0)
  1152. return r;
  1153. ioc = pci_get_drvdata(pdev);
  1154. ioc->DoneCtx = mptspiDoneCtx;
  1155. ioc->TaskCtx = mptspiTaskCtx;
  1156. ioc->InternalCtx = mptspiInternalCtx;
  1157. /* Added sanity check on readiness of the MPT adapter.
  1158. */
  1159. if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
  1160. printk(MYIOC_s_WARN_FMT
  1161. "Skipping because it's not operational!\n",
  1162. ioc->name);
  1163. error = -ENODEV;
  1164. goto out_mptspi_probe;
  1165. }
  1166. if (!ioc->active) {
  1167. printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
  1168. ioc->name);
  1169. error = -ENODEV;
  1170. goto out_mptspi_probe;
  1171. }
  1172. /* Sanity check - ensure at least 1 port is INITIATOR capable
  1173. */
  1174. ioc_cap = 0;
  1175. for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
  1176. if (ioc->pfacts[ii].ProtocolFlags &
  1177. MPI_PORTFACTS_PROTOCOL_INITIATOR)
  1178. ioc_cap ++;
  1179. }
  1180. if (!ioc_cap) {
  1181. printk(MYIOC_s_WARN_FMT
  1182. "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
  1183. ioc->name, ioc);
  1184. return 0;
  1185. }
  1186. sh = scsi_host_alloc(&mptspi_driver_template, sizeof(MPT_SCSI_HOST));
  1187. if (!sh) {
  1188. printk(MYIOC_s_WARN_FMT
  1189. "Unable to register controller with SCSI subsystem\n",
  1190. ioc->name);
  1191. error = -1;
  1192. goto out_mptspi_probe;
  1193. }
  1194. /* VMWare emulation doesn't properly implement WRITE_SAME
  1195. */
  1196. if (pdev->subsystem_vendor == 0x15AD)
  1197. sh->no_write_same = 1;
  1198. spin_lock_irqsave(&ioc->FreeQlock, flags);
  1199. /* Attach the SCSI Host to the IOC structure
  1200. */
  1201. ioc->sh = sh;
  1202. sh->io_port = 0;
  1203. sh->n_io_port = 0;
  1204. sh->irq = 0;
  1205. /* set 16 byte cdb's */
  1206. sh->max_cmd_len = 16;
  1207. /* Yikes! This is important!
  1208. * Otherwise, by default, linux
  1209. * only scans target IDs 0-7!
  1210. * pfactsN->MaxDevices unreliable
  1211. * (not supported in early
  1212. * versions of the FW).
  1213. * max_id = 1 + actual max id,
  1214. * max_lun = 1 + actual last lun,
  1215. * see hosts.h :o(
  1216. */
  1217. sh->max_id = ioc->devices_per_bus;
  1218. sh->max_lun = MPT_LAST_LUN + 1;
  1219. /*
  1220. * If RAID Firmware Detected, setup virtual channel
  1221. */
  1222. if (ioc->ir_firmware)
  1223. sh->max_channel = 1;
  1224. else
  1225. sh->max_channel = 0;
  1226. sh->this_id = ioc->pfacts[0].PortSCSIID;
  1227. /* Required entry.
  1228. */
  1229. sh->unique_id = ioc->id;
  1230. /* Verify that we won't exceed the maximum
  1231. * number of chain buffers
  1232. * We can optimize: ZZ = req_sz/sizeof(SGE)
  1233. * For 32bit SGE's:
  1234. * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
  1235. * + (req_sz - 64)/sizeof(SGE)
  1236. * A slightly different algorithm is required for
  1237. * 64bit SGEs.
  1238. */
  1239. scale = ioc->req_sz/ioc->SGE_size;
  1240. if (ioc->sg_addr_size == sizeof(u64)) {
  1241. numSGE = (scale - 1) *
  1242. (ioc->facts.MaxChainDepth-1) + scale +
  1243. (ioc->req_sz - 60) / ioc->SGE_size;
  1244. } else {
  1245. numSGE = 1 + (scale - 1) *
  1246. (ioc->facts.MaxChainDepth-1) + scale +
  1247. (ioc->req_sz - 64) / ioc->SGE_size;
  1248. }
  1249. if (numSGE < sh->sg_tablesize) {
  1250. /* Reset this value */
  1251. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1252. "Resetting sg_tablesize to %d from %d\n",
  1253. ioc->name, numSGE, sh->sg_tablesize));
  1254. sh->sg_tablesize = numSGE;
  1255. }
  1256. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  1257. hd = shost_priv(sh);
  1258. hd->ioc = ioc;
  1259. /* SCSI needs scsi_cmnd lookup table!
  1260. * (with size equal to req_depth*PtrSz!)
  1261. */
  1262. ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
  1263. if (!ioc->ScsiLookup) {
  1264. error = -ENOMEM;
  1265. goto out_mptspi_probe;
  1266. }
  1267. spin_lock_init(&ioc->scsi_lookup_lock);
  1268. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
  1269. ioc->name, ioc->ScsiLookup));
  1270. ioc->spi_data.Saf_Te = mpt_saf_te;
  1271. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1272. "saf_te %x\n",
  1273. ioc->name,
  1274. mpt_saf_te));
  1275. ioc->spi_data.noQas = 0;
  1276. hd->last_queue_full = 0;
  1277. hd->spi_pending = 0;
  1278. /* Some versions of the firmware don't support page 0; without
  1279. * that we can't get the parameters */
  1280. if (ioc->spi_data.sdp0length != 0)
  1281. sh->transportt = mptspi_transport_template;
  1282. error = scsi_add_host (sh, &ioc->pcidev->dev);
  1283. if(error) {
  1284. dprintk(ioc, printk(MYIOC_s_ERR_FMT
  1285. "scsi_add_host failed\n", ioc->name));
  1286. goto out_mptspi_probe;
  1287. }
  1288. /*
  1289. * issue internal bus reset
  1290. */
  1291. if (ioc->spi_data.bus_reset)
  1292. mptscsih_IssueTaskMgmt(hd,
  1293. MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
  1294. 0, 0, 0, 0, 5);
  1295. scsi_scan_host(sh);
  1296. return 0;
  1297. out_mptspi_probe:
  1298. mptscsih_remove(pdev);
  1299. return error;
  1300. }
  1301. static struct pci_driver mptspi_driver = {
  1302. .name = "mptspi",
  1303. .id_table = mptspi_pci_table,
  1304. .probe = mptspi_probe,
  1305. .remove = mptscsih_remove,
  1306. .shutdown = mptscsih_shutdown,
  1307. #ifdef CONFIG_PM
  1308. .suspend = mptscsih_suspend,
  1309. .resume = mptspi_resume,
  1310. #endif
  1311. };
  1312. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1313. /**
  1314. * mptspi_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer.
  1315. *
  1316. * Returns 0 for success, non-zero for failure.
  1317. */
  1318. static int __init
  1319. mptspi_init(void)
  1320. {
  1321. int error;
  1322. show_mptmod_ver(my_NAME, my_VERSION);
  1323. mptspi_transport_template = spi_attach_transport(&mptspi_transport_functions);
  1324. if (!mptspi_transport_template)
  1325. return -ENODEV;
  1326. mptspiDoneCtx = mpt_register(mptscsih_io_done, MPTSPI_DRIVER,
  1327. "mptscsih_io_done");
  1328. mptspiTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSPI_DRIVER,
  1329. "mptscsih_taskmgmt_complete");
  1330. mptspiInternalCtx = mpt_register(mptscsih_scandv_complete,
  1331. MPTSPI_DRIVER, "mptscsih_scandv_complete");
  1332. mpt_event_register(mptspiDoneCtx, mptspi_event_process);
  1333. mpt_reset_register(mptspiDoneCtx, mptspi_ioc_reset);
  1334. error = pci_register_driver(&mptspi_driver);
  1335. if (error)
  1336. spi_release_transport(mptspi_transport_template);
  1337. return error;
  1338. }
  1339. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1340. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1341. /**
  1342. * mptspi_exit - Unregisters MPT adapter(s)
  1343. */
  1344. static void __exit
  1345. mptspi_exit(void)
  1346. {
  1347. pci_unregister_driver(&mptspi_driver);
  1348. mpt_reset_deregister(mptspiDoneCtx);
  1349. mpt_event_deregister(mptspiDoneCtx);
  1350. mpt_deregister(mptspiInternalCtx);
  1351. mpt_deregister(mptspiTaskCtx);
  1352. mpt_deregister(mptspiDoneCtx);
  1353. spi_release_transport(mptspi_transport_template);
  1354. }
  1355. module_init(mptspi_init);
  1356. module_exit(mptspi_exit);