mptspi.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. /*
  2. * linux/drivers/message/fusion/mptspi.c
  3. * For use with LSI Logic PCI chip/adapter(s)
  4. * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
  5. *
  6. * Copyright (c) 1999-2005 LSI Logic Corporation
  7. * (mailto:mpt_linux_developer@lsil.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_compat.h" /* linux-2.6 tweaks */
  43. #include <linux/module.h>
  44. #include <linux/kernel.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/sched.h>
  53. #include <linux/workqueue.h>
  54. #include <linux/raid_class.h>
  55. #include <scsi/scsi.h>
  56. #include <scsi/scsi_cmnd.h>
  57. #include <scsi/scsi_device.h>
  58. #include <scsi/scsi_host.h>
  59. #include <scsi/scsi_tcq.h>
  60. #include <scsi/scsi_transport.h>
  61. #include <scsi/scsi_transport_spi.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. /* Command line args */
  72. static int mpt_saf_te = MPTSCSIH_SAF_TE;
  73. module_param(mpt_saf_te, int, 0);
  74. MODULE_PARM_DESC(mpt_saf_te, " Force enabling SEP Processor: enable=1 (default=MPTSCSIH_SAF_TE=0)");
  75. static int mpt_pq_filter = 0;
  76. module_param(mpt_pq_filter, int, 0);
  77. MODULE_PARM_DESC(mpt_pq_filter, " Enable peripheral qualifier filter: enable=1 (default=0)");
  78. static void mptspi_write_offset(struct scsi_target *, int);
  79. static void mptspi_write_width(struct scsi_target *, int);
  80. static int mptspi_write_spi_device_pg1(struct scsi_target *,
  81. struct _CONFIG_PAGE_SCSI_DEVICE_1 *);
  82. static struct scsi_transport_template *mptspi_transport_template = NULL;
  83. static int mptspiDoneCtx = -1;
  84. static int mptspiTaskCtx = -1;
  85. static int mptspiInternalCtx = -1; /* Used only for internal commands */
  86. static int mptspi_target_alloc(struct scsi_target *starget)
  87. {
  88. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  89. struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
  90. int ret;
  91. if (hd == NULL)
  92. return -ENODEV;
  93. ret = mptscsih_target_alloc(starget);
  94. if (ret)
  95. return ret;
  96. /* if we're a device on virtual channel 1 and we're not part
  97. * of an array, just return here (otherwise the setup below
  98. * may actually affect a real physical device on channel 0 */
  99. if (starget->channel == 1 &&
  100. mptscsih_raid_id_to_num(hd, starget->id) < 0)
  101. return 0;
  102. if (hd->ioc->spi_data.nvram &&
  103. hd->ioc->spi_data.nvram[starget->id] != MPT_HOST_NVRAM_INVALID) {
  104. u32 nvram = hd->ioc->spi_data.nvram[starget->id];
  105. spi_min_period(starget) = (nvram & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
  106. spi_max_width(starget) = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
  107. } else {
  108. spi_min_period(starget) = hd->ioc->spi_data.minSyncFactor;
  109. spi_max_width(starget) = hd->ioc->spi_data.maxBusWidth;
  110. }
  111. spi_max_offset(starget) = hd->ioc->spi_data.maxSyncOffset;
  112. spi_offset(starget) = 0;
  113. mptspi_write_width(starget, 0);
  114. return 0;
  115. }
  116. static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
  117. struct _CONFIG_PAGE_SCSI_DEVICE_0 *pass_pg0)
  118. {
  119. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  120. struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
  121. struct _MPT_ADAPTER *ioc = hd->ioc;
  122. struct _CONFIG_PAGE_SCSI_DEVICE_0 *pg0;
  123. dma_addr_t pg0_dma;
  124. int size;
  125. struct _x_config_parms cfg;
  126. struct _CONFIG_PAGE_HEADER hdr;
  127. int err = -EBUSY;
  128. /* No SPI parameters for RAID devices */
  129. if (starget->channel == 0 &&
  130. (hd->ioc->raid_data.isRaid & (1 << starget->id)))
  131. return -1;
  132. size = ioc->spi_data.sdp0length * 4;
  133. /*
  134. if (ioc->spi_data.sdp0length & 1)
  135. size += size + 4;
  136. size += 2048;
  137. */
  138. pg0 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg0_dma, GFP_KERNEL);
  139. if (pg0 == NULL) {
  140. starget_printk(KERN_ERR, starget, "dma_alloc_coherent for parameters failed\n");
  141. return -EINVAL;
  142. }
  143. memset(&hdr, 0, sizeof(hdr));
  144. hdr.PageVersion = ioc->spi_data.sdp0version;
  145. hdr.PageLength = ioc->spi_data.sdp0length;
  146. hdr.PageNumber = 0;
  147. hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  148. memset(&cfg, 0, sizeof(cfg));
  149. cfg.cfghdr.hdr = &hdr;
  150. cfg.physAddr = pg0_dma;
  151. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  152. cfg.dir = 0;
  153. cfg.pageAddr = starget->id;
  154. if (mpt_config(ioc, &cfg)) {
  155. starget_printk(KERN_ERR, starget, "mpt_config failed\n");
  156. goto out_free;
  157. }
  158. err = 0;
  159. memcpy(pass_pg0, pg0, size);
  160. out_free:
  161. dma_free_coherent(&ioc->pcidev->dev, size, pg0, pg0_dma);
  162. return err;
  163. }
  164. static u32 mptspi_getRP(struct scsi_target *starget)
  165. {
  166. u32 nego = 0;
  167. nego |= spi_iu(starget) ? MPI_SCSIDEVPAGE1_RP_IU : 0;
  168. nego |= spi_dt(starget) ? MPI_SCSIDEVPAGE1_RP_DT : 0;
  169. nego |= spi_qas(starget) ? MPI_SCSIDEVPAGE1_RP_QAS : 0;
  170. nego |= spi_hold_mcs(starget) ? MPI_SCSIDEVPAGE1_RP_HOLD_MCS : 0;
  171. nego |= spi_wr_flow(starget) ? MPI_SCSIDEVPAGE1_RP_WR_FLOW : 0;
  172. nego |= spi_rd_strm(starget) ? MPI_SCSIDEVPAGE1_RP_RD_STRM : 0;
  173. nego |= spi_rti(starget) ? MPI_SCSIDEVPAGE1_RP_RTI : 0;
  174. nego |= spi_pcomp_en(starget) ? MPI_SCSIDEVPAGE1_RP_PCOMP_EN : 0;
  175. nego |= (spi_period(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD) & MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK;
  176. nego |= (spi_offset(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MAX_SYNC_OFFSET) & MPI_SCSIDEVPAGE1_RP_MAX_SYNC_OFFSET_MASK;
  177. nego |= spi_width(starget) ? MPI_SCSIDEVPAGE1_RP_WIDE : 0;
  178. return nego;
  179. }
  180. static void mptspi_read_parameters(struct scsi_target *starget)
  181. {
  182. int nego;
  183. struct _CONFIG_PAGE_SCSI_DEVICE_0 pg0;
  184. mptspi_read_spi_device_pg0(starget, &pg0);
  185. nego = le32_to_cpu(pg0.NegotiatedParameters);
  186. spi_iu(starget) = (nego & MPI_SCSIDEVPAGE0_NP_IU) ? 1 : 0;
  187. spi_dt(starget) = (nego & MPI_SCSIDEVPAGE0_NP_DT) ? 1 : 0;
  188. spi_qas(starget) = (nego & MPI_SCSIDEVPAGE0_NP_QAS) ? 1 : 0;
  189. spi_wr_flow(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WR_FLOW) ? 1 : 0;
  190. spi_rd_strm(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RD_STRM) ? 1 : 0;
  191. spi_rti(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RTI) ? 1 : 0;
  192. spi_pcomp_en(starget) = (nego & MPI_SCSIDEVPAGE0_NP_PCOMP_EN) ? 1 : 0;
  193. spi_hold_mcs(starget) = (nego & MPI_SCSIDEVPAGE0_NP_HOLD_MCS) ? 1 : 0;
  194. spi_period(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_PERIOD;
  195. spi_offset(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_OFFSET;
  196. spi_width(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WIDE) ? 1 : 0;
  197. }
  198. static int
  199. mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, int disk)
  200. {
  201. MpiRaidActionRequest_t *pReq;
  202. MPT_FRAME_HDR *mf;
  203. /* Get and Populate a free Frame
  204. */
  205. if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) {
  206. ddvprintk((MYIOC_s_WARN_FMT "_do_raid: no msg frames!\n",
  207. hd->ioc->name));
  208. return -EAGAIN;
  209. }
  210. pReq = (MpiRaidActionRequest_t *)mf;
  211. if (quiesce)
  212. pReq->Action = MPI_RAID_ACTION_QUIESCE_PHYS_IO;
  213. else
  214. pReq->Action = MPI_RAID_ACTION_ENABLE_PHYS_IO;
  215. pReq->Reserved1 = 0;
  216. pReq->ChainOffset = 0;
  217. pReq->Function = MPI_FUNCTION_RAID_ACTION;
  218. pReq->VolumeID = disk;
  219. pReq->VolumeBus = 0;
  220. pReq->PhysDiskNum = 0;
  221. pReq->MsgFlags = 0;
  222. pReq->Reserved2 = 0;
  223. pReq->ActionDataWord = 0; /* Reserved for this action */
  224. mpt_add_sge((char *)&pReq->ActionDataSGE,
  225. MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
  226. ddvprintk((MYIOC_s_INFO_FMT "RAID Volume action %x id %d\n",
  227. hd->ioc->name, action, io->id));
  228. hd->pLocal = NULL;
  229. hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */
  230. hd->scandv_wait_done = 0;
  231. /* Save cmd pointer, for resource free if timeout or
  232. * FW reload occurs
  233. */
  234. hd->cmdPtr = mf;
  235. add_timer(&hd->timer);
  236. mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf);
  237. wait_event(hd->scandv_waitq, hd->scandv_wait_done);
  238. if ((hd->pLocal == NULL) || (hd->pLocal->completion != 0))
  239. return -1;
  240. return 0;
  241. }
  242. static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
  243. struct scsi_device *sdev)
  244. {
  245. VirtTarget *vtarget = scsi_target(sdev)->hostdata;
  246. /* no DV on RAID devices */
  247. if (sdev->channel == 0 &&
  248. (hd->ioc->raid_data.isRaid & (1 << sdev->id)))
  249. return;
  250. /* If this is a piece of a RAID, then quiesce first */
  251. if (sdev->channel == 1 &&
  252. mptscsih_quiesce_raid(hd, 1, vtarget->target_id) < 0) {
  253. starget_printk(KERN_ERR, scsi_target(sdev),
  254. "Integrated RAID quiesce failed\n");
  255. return;
  256. }
  257. spi_dv_device(sdev);
  258. if (sdev->channel == 1 &&
  259. mptscsih_quiesce_raid(hd, 0, vtarget->target_id) < 0)
  260. starget_printk(KERN_ERR, scsi_target(sdev),
  261. "Integrated RAID resume failed\n");
  262. mptspi_read_parameters(sdev->sdev_target);
  263. spi_display_xfer_agreement(sdev->sdev_target);
  264. mptspi_read_parameters(sdev->sdev_target);
  265. }
  266. static int mptspi_slave_alloc(struct scsi_device *sdev)
  267. {
  268. int ret;
  269. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
  270. /* gcc doesn't see that all uses of this variable occur within
  271. * the if() statements, so stop it from whining */
  272. int physdisknum = 0;
  273. if (sdev->channel == 1) {
  274. physdisknum = mptscsih_raid_id_to_num(hd, sdev->id);
  275. if (physdisknum < 0)
  276. return physdisknum;
  277. }
  278. ret = mptscsih_slave_alloc(sdev);
  279. if (ret)
  280. return ret;
  281. if (sdev->channel == 1) {
  282. VirtDevice *vdev = sdev->hostdata;
  283. sdev->no_uld_attach = 1;
  284. vdev->vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
  285. /* The real channel for this device is zero */
  286. vdev->vtarget->bus_id = 0;
  287. /* The actual physdisknum (for RAID passthrough) */
  288. vdev->vtarget->target_id = physdisknum;
  289. }
  290. return 0;
  291. }
  292. static int mptspi_slave_configure(struct scsi_device *sdev)
  293. {
  294. int ret = mptscsih_slave_configure(sdev);
  295. struct _MPT_SCSI_HOST *hd =
  296. (struct _MPT_SCSI_HOST *)sdev->host->hostdata;
  297. if (ret)
  298. return ret;
  299. if ((sdev->channel == 1 ||
  300. !(hd->ioc->raid_data.isRaid & (1 << sdev->id))) &&
  301. !spi_initial_dv(sdev->sdev_target))
  302. mptspi_dv_device(hd, sdev);
  303. return 0;
  304. }
  305. static void mptspi_slave_destroy(struct scsi_device *sdev)
  306. {
  307. struct scsi_target *starget = scsi_target(sdev);
  308. VirtTarget *vtarget = starget->hostdata;
  309. VirtDevice *vdevice = sdev->hostdata;
  310. /* Will this be the last lun on a non-raid device? */
  311. if (vtarget->num_luns == 1 && vdevice->configured_lun) {
  312. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  313. /* Async Narrow */
  314. pg1.RequestedParameters = 0;
  315. pg1.Reserved = 0;
  316. pg1.Configuration = 0;
  317. mptspi_write_spi_device_pg1(starget, &pg1);
  318. }
  319. mptscsih_slave_destroy(sdev);
  320. }
  321. static struct scsi_host_template mptspi_driver_template = {
  322. .module = THIS_MODULE,
  323. .proc_name = "mptspi",
  324. .proc_info = mptscsih_proc_info,
  325. .name = "MPT SPI Host",
  326. .info = mptscsih_info,
  327. .queuecommand = mptscsih_qcmd,
  328. .target_alloc = mptspi_target_alloc,
  329. .slave_alloc = mptspi_slave_alloc,
  330. .slave_configure = mptspi_slave_configure,
  331. .target_destroy = mptscsih_target_destroy,
  332. .slave_destroy = mptspi_slave_destroy,
  333. .change_queue_depth = mptscsih_change_queue_depth,
  334. .eh_abort_handler = mptscsih_abort,
  335. .eh_device_reset_handler = mptscsih_dev_reset,
  336. .eh_bus_reset_handler = mptscsih_bus_reset,
  337. .eh_host_reset_handler = mptscsih_host_reset,
  338. .bios_param = mptscsih_bios_param,
  339. .can_queue = MPT_SCSI_CAN_QUEUE,
  340. .this_id = -1,
  341. .sg_tablesize = MPT_SCSI_SG_DEPTH,
  342. .max_sectors = 8192,
  343. .cmd_per_lun = 7,
  344. .use_clustering = ENABLE_CLUSTERING,
  345. };
  346. static int mptspi_write_spi_device_pg1(struct scsi_target *starget,
  347. struct _CONFIG_PAGE_SCSI_DEVICE_1 *pass_pg1)
  348. {
  349. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  350. struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
  351. struct _MPT_ADAPTER *ioc = hd->ioc;
  352. struct _CONFIG_PAGE_SCSI_DEVICE_1 *pg1;
  353. dma_addr_t pg1_dma;
  354. int size;
  355. struct _x_config_parms cfg;
  356. struct _CONFIG_PAGE_HEADER hdr;
  357. int err = -EBUSY;
  358. /* don't allow updating nego parameters on RAID devices */
  359. if (starget->channel == 0 &&
  360. (hd->ioc->raid_data.isRaid & (1 << starget->id)))
  361. return -1;
  362. size = ioc->spi_data.sdp1length * 4;
  363. pg1 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg1_dma, GFP_KERNEL);
  364. if (pg1 == NULL) {
  365. starget_printk(KERN_ERR, starget, "dma_alloc_coherent for parameters failed\n");
  366. return -EINVAL;
  367. }
  368. memset(&hdr, 0, sizeof(hdr));
  369. hdr.PageVersion = ioc->spi_data.sdp1version;
  370. hdr.PageLength = ioc->spi_data.sdp1length;
  371. hdr.PageNumber = 1;
  372. hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  373. memset(&cfg, 0, sizeof(cfg));
  374. cfg.cfghdr.hdr = &hdr;
  375. cfg.physAddr = pg1_dma;
  376. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  377. cfg.dir = 1;
  378. cfg.pageAddr = starget->id;
  379. memcpy(pg1, pass_pg1, size);
  380. pg1->Header.PageVersion = hdr.PageVersion;
  381. pg1->Header.PageLength = hdr.PageLength;
  382. pg1->Header.PageNumber = hdr.PageNumber;
  383. pg1->Header.PageType = hdr.PageType;
  384. if (mpt_config(ioc, &cfg)) {
  385. starget_printk(KERN_ERR, starget, "mpt_config failed\n");
  386. goto out_free;
  387. }
  388. err = 0;
  389. out_free:
  390. dma_free_coherent(&ioc->pcidev->dev, size, pg1, pg1_dma);
  391. return err;
  392. }
  393. static void mptspi_write_offset(struct scsi_target *starget, int offset)
  394. {
  395. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  396. u32 nego;
  397. if (offset < 0)
  398. offset = 0;
  399. if (offset > 255)
  400. offset = 255;
  401. if (spi_offset(starget) == -1)
  402. mptspi_read_parameters(starget);
  403. spi_offset(starget) = offset;
  404. nego = mptspi_getRP(starget);
  405. pg1.RequestedParameters = cpu_to_le32(nego);
  406. pg1.Reserved = 0;
  407. pg1.Configuration = 0;
  408. mptspi_write_spi_device_pg1(starget, &pg1);
  409. }
  410. static void mptspi_write_period(struct scsi_target *starget, int period)
  411. {
  412. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  413. u32 nego;
  414. if (period < 8)
  415. period = 8;
  416. if (period > 255)
  417. period = 255;
  418. if (spi_period(starget) == -1)
  419. mptspi_read_parameters(starget);
  420. if (period == 8) {
  421. spi_iu(starget) = 1;
  422. spi_dt(starget) = 1;
  423. } else if (period == 9) {
  424. spi_dt(starget) = 1;
  425. }
  426. spi_period(starget) = period;
  427. nego = mptspi_getRP(starget);
  428. pg1.RequestedParameters = cpu_to_le32(nego);
  429. pg1.Reserved = 0;
  430. pg1.Configuration = 0;
  431. mptspi_write_spi_device_pg1(starget, &pg1);
  432. }
  433. static void mptspi_write_dt(struct scsi_target *starget, int dt)
  434. {
  435. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  436. u32 nego;
  437. if (spi_period(starget) == -1)
  438. mptspi_read_parameters(starget);
  439. if (!dt && spi_period(starget) < 10)
  440. spi_period(starget) = 10;
  441. spi_dt(starget) = dt;
  442. nego = mptspi_getRP(starget);
  443. pg1.RequestedParameters = cpu_to_le32(nego);
  444. pg1.Reserved = 0;
  445. pg1.Configuration = 0;
  446. mptspi_write_spi_device_pg1(starget, &pg1);
  447. }
  448. static void mptspi_write_iu(struct scsi_target *starget, int iu)
  449. {
  450. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  451. u32 nego;
  452. if (spi_period(starget) == -1)
  453. mptspi_read_parameters(starget);
  454. if (!iu && spi_period(starget) < 9)
  455. spi_period(starget) = 9;
  456. spi_iu(starget) = iu;
  457. nego = mptspi_getRP(starget);
  458. pg1.RequestedParameters = cpu_to_le32(nego);
  459. pg1.Reserved = 0;
  460. pg1.Configuration = 0;
  461. mptspi_write_spi_device_pg1(starget, &pg1);
  462. }
  463. #define MPTSPI_SIMPLE_TRANSPORT_PARM(parm) \
  464. static void mptspi_write_##parm(struct scsi_target *starget, int parm)\
  465. { \
  466. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; \
  467. u32 nego; \
  468. \
  469. spi_##parm(starget) = parm; \
  470. \
  471. nego = mptspi_getRP(starget); \
  472. \
  473. pg1.RequestedParameters = cpu_to_le32(nego); \
  474. pg1.Reserved = 0; \
  475. pg1.Configuration = 0; \
  476. \
  477. mptspi_write_spi_device_pg1(starget, &pg1); \
  478. }
  479. MPTSPI_SIMPLE_TRANSPORT_PARM(rd_strm)
  480. MPTSPI_SIMPLE_TRANSPORT_PARM(wr_flow)
  481. MPTSPI_SIMPLE_TRANSPORT_PARM(rti)
  482. MPTSPI_SIMPLE_TRANSPORT_PARM(hold_mcs)
  483. MPTSPI_SIMPLE_TRANSPORT_PARM(pcomp_en)
  484. static void mptspi_write_qas(struct scsi_target *starget, int qas)
  485. {
  486. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  487. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  488. struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
  489. VirtTarget *vtarget = starget->hostdata;
  490. u32 nego;
  491. if ((vtarget->negoFlags & MPT_TARGET_NO_NEGO_QAS) ||
  492. hd->ioc->spi_data.noQas)
  493. spi_qas(starget) = 0;
  494. else
  495. spi_qas(starget) = qas;
  496. nego = mptspi_getRP(starget);
  497. pg1.RequestedParameters = cpu_to_le32(nego);
  498. pg1.Reserved = 0;
  499. pg1.Configuration = 0;
  500. mptspi_write_spi_device_pg1(starget, &pg1);
  501. }
  502. static void mptspi_write_width(struct scsi_target *starget, int width)
  503. {
  504. struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
  505. u32 nego;
  506. if (!width) {
  507. spi_dt(starget) = 0;
  508. if (spi_period(starget) < 10)
  509. spi_period(starget) = 10;
  510. }
  511. spi_width(starget) = width;
  512. nego = mptspi_getRP(starget);
  513. pg1.RequestedParameters = cpu_to_le32(nego);
  514. pg1.Reserved = 0;
  515. pg1.Configuration = 0;
  516. mptspi_write_spi_device_pg1(starget, &pg1);
  517. }
  518. struct work_queue_wrapper {
  519. struct work_struct work;
  520. struct _MPT_SCSI_HOST *hd;
  521. int disk;
  522. };
  523. static void mpt_work_wrapper(void *data)
  524. {
  525. struct work_queue_wrapper *wqw = (struct work_queue_wrapper *)data;
  526. struct _MPT_SCSI_HOST *hd = wqw->hd;
  527. struct Scsi_Host *shost = hd->ioc->sh;
  528. struct scsi_device *sdev;
  529. int disk = wqw->disk;
  530. struct _CONFIG_PAGE_IOC_3 *pg3;
  531. kfree(wqw);
  532. mpt_findImVolumes(hd->ioc);
  533. pg3 = hd->ioc->raid_data.pIocPg3;
  534. if (!pg3)
  535. return;
  536. shost_for_each_device(sdev,shost) {
  537. struct scsi_target *starget = scsi_target(sdev);
  538. VirtTarget *vtarget = starget->hostdata;
  539. /* only want to search RAID components */
  540. if (sdev->channel != 1)
  541. continue;
  542. /* The target_id is the raid PhysDiskNum, even if
  543. * starget->id is the actual target address */
  544. if(vtarget->target_id != disk)
  545. continue;
  546. starget_printk(KERN_INFO, vtarget->starget,
  547. "Integrated RAID requests DV of new device\n");
  548. mptspi_dv_device(hd, sdev);
  549. }
  550. shost_printk(KERN_INFO, shost,
  551. "Integrated RAID detects new device %d\n", disk);
  552. scsi_scan_target(&hd->ioc->sh->shost_gendev, 1, disk, 0, 1);
  553. }
  554. static void mpt_dv_raid(struct _MPT_SCSI_HOST *hd, int disk)
  555. {
  556. struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC);
  557. if (!wqw) {
  558. shost_printk(KERN_ERR, hd->ioc->sh,
  559. "Failed to act on RAID event for physical disk %d\n",
  560. disk);
  561. return;
  562. }
  563. INIT_WORK(&wqw->work, mpt_work_wrapper, wqw);
  564. wqw->hd = hd;
  565. wqw->disk = disk;
  566. schedule_work(&wqw->work);
  567. }
  568. static int
  569. mptspi_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
  570. {
  571. u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
  572. struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)ioc->sh->hostdata;
  573. if (hd && event == MPI_EVENT_INTEGRATED_RAID) {
  574. int reason
  575. = (le32_to_cpu(pEvReply->Data[0]) & 0x00FF0000) >> 16;
  576. if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
  577. int disk = (le32_to_cpu(pEvReply->Data[0]) & 0xFF000000) >> 24;
  578. mpt_dv_raid(hd, disk);
  579. }
  580. }
  581. return mptscsih_event_process(ioc, pEvReply);
  582. }
  583. static int
  584. mptspi_deny_binding(struct scsi_target *starget)
  585. {
  586. struct _MPT_SCSI_HOST *hd =
  587. (struct _MPT_SCSI_HOST *)dev_to_shost(starget->dev.parent)->hostdata;
  588. return ((hd->ioc->raid_data.isRaid & (1 << starget->id)) &&
  589. starget->channel == 0) ? 1 : 0;
  590. }
  591. static struct spi_function_template mptspi_transport_functions = {
  592. .get_offset = mptspi_read_parameters,
  593. .set_offset = mptspi_write_offset,
  594. .show_offset = 1,
  595. .get_period = mptspi_read_parameters,
  596. .set_period = mptspi_write_period,
  597. .show_period = 1,
  598. .get_width = mptspi_read_parameters,
  599. .set_width = mptspi_write_width,
  600. .show_width = 1,
  601. .get_iu = mptspi_read_parameters,
  602. .set_iu = mptspi_write_iu,
  603. .show_iu = 1,
  604. .get_dt = mptspi_read_parameters,
  605. .set_dt = mptspi_write_dt,
  606. .show_dt = 1,
  607. .get_qas = mptspi_read_parameters,
  608. .set_qas = mptspi_write_qas,
  609. .show_qas = 1,
  610. .get_wr_flow = mptspi_read_parameters,
  611. .set_wr_flow = mptspi_write_wr_flow,
  612. .show_wr_flow = 1,
  613. .get_rd_strm = mptspi_read_parameters,
  614. .set_rd_strm = mptspi_write_rd_strm,
  615. .show_rd_strm = 1,
  616. .get_rti = mptspi_read_parameters,
  617. .set_rti = mptspi_write_rti,
  618. .show_rti = 1,
  619. .get_pcomp_en = mptspi_read_parameters,
  620. .set_pcomp_en = mptspi_write_pcomp_en,
  621. .show_pcomp_en = 1,
  622. .get_hold_mcs = mptspi_read_parameters,
  623. .set_hold_mcs = mptspi_write_hold_mcs,
  624. .show_hold_mcs = 1,
  625. .deny_binding = mptspi_deny_binding,
  626. };
  627. /****************************************************************************
  628. * Supported hardware
  629. */
  630. static struct pci_device_id mptspi_pci_table[] = {
  631. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1030,
  632. PCI_ANY_ID, PCI_ANY_ID },
  633. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_1030_53C1035,
  634. PCI_ANY_ID, PCI_ANY_ID },
  635. {0} /* Terminating entry */
  636. };
  637. MODULE_DEVICE_TABLE(pci, mptspi_pci_table);
  638. /*
  639. * renegotiate for a given target
  640. */
  641. static void
  642. mptspi_dv_renegotiate_work(void *data)
  643. {
  644. struct work_queue_wrapper *wqw = (struct work_queue_wrapper *)data;
  645. struct _MPT_SCSI_HOST *hd = wqw->hd;
  646. struct scsi_device *sdev;
  647. kfree(wqw);
  648. shost_for_each_device(sdev, hd->ioc->sh)
  649. mptspi_dv_device(hd, sdev);
  650. }
  651. static void
  652. mptspi_dv_renegotiate(struct _MPT_SCSI_HOST *hd)
  653. {
  654. struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC);
  655. if (!wqw)
  656. return;
  657. INIT_WORK(&wqw->work, mptspi_dv_renegotiate_work, wqw);
  658. wqw->hd = hd;
  659. schedule_work(&wqw->work);
  660. }
  661. /*
  662. * spi module reset handler
  663. */
  664. static int
  665. mptspi_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  666. {
  667. struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)ioc->sh->hostdata;
  668. int rc;
  669. rc = mptscsih_ioc_reset(ioc, reset_phase);
  670. if (reset_phase == MPT_IOC_POST_RESET)
  671. mptspi_dv_renegotiate(hd);
  672. return rc;
  673. }
  674. /*
  675. * spi module resume handler
  676. */
  677. static int
  678. mptspi_resume(struct pci_dev *pdev)
  679. {
  680. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  681. struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)ioc->sh->hostdata;
  682. int rc;
  683. rc = mptscsih_resume(pdev);
  684. mptspi_dv_renegotiate(hd);
  685. return rc;
  686. }
  687. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  688. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  689. /*
  690. * mptspi_probe - Installs scsi devices per bus.
  691. * @pdev: Pointer to pci_dev structure
  692. *
  693. * Returns 0 for success, non-zero for failure.
  694. *
  695. */
  696. static int
  697. mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  698. {
  699. struct Scsi_Host *sh;
  700. MPT_SCSI_HOST *hd;
  701. MPT_ADAPTER *ioc;
  702. unsigned long flags;
  703. int ii;
  704. int numSGE = 0;
  705. int scale;
  706. int ioc_cap;
  707. int error=0;
  708. int r;
  709. if ((r = mpt_attach(pdev,id)) != 0)
  710. return r;
  711. ioc = pci_get_drvdata(pdev);
  712. ioc->DoneCtx = mptspiDoneCtx;
  713. ioc->TaskCtx = mptspiTaskCtx;
  714. ioc->InternalCtx = mptspiInternalCtx;
  715. /* Added sanity check on readiness of the MPT adapter.
  716. */
  717. if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
  718. printk(MYIOC_s_WARN_FMT
  719. "Skipping because it's not operational!\n",
  720. ioc->name);
  721. error = -ENODEV;
  722. goto out_mptspi_probe;
  723. }
  724. if (!ioc->active) {
  725. printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
  726. ioc->name);
  727. error = -ENODEV;
  728. goto out_mptspi_probe;
  729. }
  730. /* Sanity check - ensure at least 1 port is INITIATOR capable
  731. */
  732. ioc_cap = 0;
  733. for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
  734. if (ioc->pfacts[ii].ProtocolFlags &
  735. MPI_PORTFACTS_PROTOCOL_INITIATOR)
  736. ioc_cap ++;
  737. }
  738. if (!ioc_cap) {
  739. printk(MYIOC_s_WARN_FMT
  740. "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
  741. ioc->name, ioc);
  742. return 0;
  743. }
  744. sh = scsi_host_alloc(&mptspi_driver_template, sizeof(MPT_SCSI_HOST));
  745. if (!sh) {
  746. printk(MYIOC_s_WARN_FMT
  747. "Unable to register controller with SCSI subsystem\n",
  748. ioc->name);
  749. error = -1;
  750. goto out_mptspi_probe;
  751. }
  752. spin_lock_irqsave(&ioc->FreeQlock, flags);
  753. /* Attach the SCSI Host to the IOC structure
  754. */
  755. ioc->sh = sh;
  756. sh->io_port = 0;
  757. sh->n_io_port = 0;
  758. sh->irq = 0;
  759. /* set 16 byte cdb's */
  760. sh->max_cmd_len = 16;
  761. /* Yikes! This is important!
  762. * Otherwise, by default, linux
  763. * only scans target IDs 0-7!
  764. * pfactsN->MaxDevices unreliable
  765. * (not supported in early
  766. * versions of the FW).
  767. * max_id = 1 + actual max id,
  768. * max_lun = 1 + actual last lun,
  769. * see hosts.h :o(
  770. */
  771. sh->max_id = MPT_MAX_SCSI_DEVICES;
  772. sh->max_lun = MPT_LAST_LUN + 1;
  773. /*
  774. * If RAID Firmware Detected, setup virtual channel
  775. */
  776. if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
  777. > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
  778. sh->max_channel = 1;
  779. else
  780. sh->max_channel = 0;
  781. sh->this_id = ioc->pfacts[0].PortSCSIID;
  782. /* Required entry.
  783. */
  784. sh->unique_id = ioc->id;
  785. /* Verify that we won't exceed the maximum
  786. * number of chain buffers
  787. * We can optimize: ZZ = req_sz/sizeof(SGE)
  788. * For 32bit SGE's:
  789. * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
  790. * + (req_sz - 64)/sizeof(SGE)
  791. * A slightly different algorithm is required for
  792. * 64bit SGEs.
  793. */
  794. scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
  795. if (sizeof(dma_addr_t) == sizeof(u64)) {
  796. numSGE = (scale - 1) *
  797. (ioc->facts.MaxChainDepth-1) + scale +
  798. (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
  799. sizeof(u32));
  800. } else {
  801. numSGE = 1 + (scale - 1) *
  802. (ioc->facts.MaxChainDepth-1) + scale +
  803. (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
  804. sizeof(u32));
  805. }
  806. if (numSGE < sh->sg_tablesize) {
  807. /* Reset this value */
  808. dprintk((MYIOC_s_INFO_FMT
  809. "Resetting sg_tablesize to %d from %d\n",
  810. ioc->name, numSGE, sh->sg_tablesize));
  811. sh->sg_tablesize = numSGE;
  812. }
  813. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  814. hd = (MPT_SCSI_HOST *) sh->hostdata;
  815. hd->ioc = ioc;
  816. /* SCSI needs scsi_cmnd lookup table!
  817. * (with size equal to req_depth*PtrSz!)
  818. */
  819. hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
  820. if (!hd->ScsiLookup) {
  821. error = -ENOMEM;
  822. goto out_mptspi_probe;
  823. }
  824. dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
  825. ioc->name, hd->ScsiLookup));
  826. /* Allocate memory for the device structures.
  827. * A non-Null pointer at an offset
  828. * indicates a device exists.
  829. * max_id = 1 + maximum id (hosts.h)
  830. */
  831. hd->Targets = kcalloc(sh->max_id * (sh->max_channel + 1),
  832. sizeof(void *), GFP_ATOMIC);
  833. if (!hd->Targets) {
  834. error = -ENOMEM;
  835. goto out_mptspi_probe;
  836. }
  837. dprintk((KERN_INFO " vdev @ %p\n", hd->Targets));
  838. /* Clear the TM flags
  839. */
  840. hd->tmPending = 0;
  841. hd->tmState = TM_STATE_NONE;
  842. hd->resetPending = 0;
  843. hd->abortSCpnt = NULL;
  844. /* Clear the pointer used to store
  845. * single-threaded commands, i.e., those
  846. * issued during a bus scan, dv and
  847. * configuration pages.
  848. */
  849. hd->cmdPtr = NULL;
  850. /* Initialize this SCSI Hosts' timers
  851. * To use, set the timer expires field
  852. * and add_timer
  853. */
  854. init_timer(&hd->timer);
  855. hd->timer.data = (unsigned long) hd;
  856. hd->timer.function = mptscsih_timer_expired;
  857. ioc->spi_data.Saf_Te = mpt_saf_te;
  858. hd->mpt_pq_filter = mpt_pq_filter;
  859. hd->negoNvram = MPT_SCSICFG_USE_NVRAM;
  860. ddvprintk((MYIOC_s_INFO_FMT
  861. "saf_te %x mpt_pq_filter %x\n",
  862. ioc->name,
  863. mpt_saf_te,
  864. mpt_pq_filter));
  865. ioc->spi_data.noQas = 0;
  866. init_waitqueue_head(&hd->scandv_waitq);
  867. hd->scandv_wait_done = 0;
  868. hd->last_queue_full = 0;
  869. /* Some versions of the firmware don't support page 0; without
  870. * that we can't get the parameters */
  871. if (hd->ioc->spi_data.sdp0length != 0)
  872. sh->transportt = mptspi_transport_template;
  873. error = scsi_add_host (sh, &ioc->pcidev->dev);
  874. if(error) {
  875. dprintk((KERN_ERR MYNAM
  876. "scsi_add_host failed\n"));
  877. goto out_mptspi_probe;
  878. }
  879. /*
  880. * issue internal bus reset
  881. */
  882. if (ioc->spi_data.bus_reset)
  883. mptscsih_TMHandler(hd,
  884. MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
  885. 0, 0, 0, 0, 5);
  886. scsi_scan_host(sh);
  887. return 0;
  888. out_mptspi_probe:
  889. mptscsih_remove(pdev);
  890. return error;
  891. }
  892. static struct pci_driver mptspi_driver = {
  893. .name = "mptspi",
  894. .id_table = mptspi_pci_table,
  895. .probe = mptspi_probe,
  896. .remove = __devexit_p(mptscsih_remove),
  897. .shutdown = mptscsih_shutdown,
  898. #ifdef CONFIG_PM
  899. .suspend = mptscsih_suspend,
  900. .resume = mptspi_resume,
  901. #endif
  902. };
  903. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  904. /**
  905. * mptspi_init - Register MPT adapter(s) as SCSI host(s) with
  906. * linux scsi mid-layer.
  907. *
  908. * Returns 0 for success, non-zero for failure.
  909. */
  910. static int __init
  911. mptspi_init(void)
  912. {
  913. show_mptmod_ver(my_NAME, my_VERSION);
  914. mptspi_transport_template = spi_attach_transport(&mptspi_transport_functions);
  915. if (!mptspi_transport_template)
  916. return -ENODEV;
  917. mptspiDoneCtx = mpt_register(mptscsih_io_done, MPTSPI_DRIVER);
  918. mptspiTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSPI_DRIVER);
  919. mptspiInternalCtx = mpt_register(mptscsih_scandv_complete, MPTSPI_DRIVER);
  920. if (mpt_event_register(mptspiDoneCtx, mptspi_event_process) == 0) {
  921. devtverboseprintk((KERN_INFO MYNAM
  922. ": Registered for IOC event notifications\n"));
  923. }
  924. if (mpt_reset_register(mptspiDoneCtx, mptspi_ioc_reset) == 0) {
  925. dprintk((KERN_INFO MYNAM
  926. ": Registered for IOC reset notifications\n"));
  927. }
  928. return pci_register_driver(&mptspi_driver);
  929. }
  930. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  931. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  932. /**
  933. * mptspi_exit - Unregisters MPT adapter(s)
  934. *
  935. */
  936. static void __exit
  937. mptspi_exit(void)
  938. {
  939. pci_unregister_driver(&mptspi_driver);
  940. mpt_reset_deregister(mptspiDoneCtx);
  941. dprintk((KERN_INFO MYNAM
  942. ": Deregistered for IOC reset notifications\n"));
  943. mpt_event_deregister(mptspiDoneCtx);
  944. dprintk((KERN_INFO MYNAM
  945. ": Deregistered for IOC event notifications\n"));
  946. mpt_deregister(mptspiInternalCtx);
  947. mpt_deregister(mptspiTaskCtx);
  948. mpt_deregister(mptspiDoneCtx);
  949. spi_release_transport(mptspi_transport_template);
  950. }
  951. module_init(mptspi_init);
  952. module_exit(mptspi_exit);