mptspi.c 43 KB

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