mptfc.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  1. /*
  2. * linux/drivers/message/fusion/mptfc.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/init.h>
  45. #include <linux/errno.h>
  46. #include <linux/kdev_t.h>
  47. #include <linux/blkdev.h>
  48. #include <linux/delay.h> /* for mdelay */
  49. #include <linux/interrupt.h>
  50. #include <linux/reboot.h> /* notifier code */
  51. #include <linux/workqueue.h>
  52. #include <linux/sort.h>
  53. #include <linux/slab.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_fc.h>
  60. #include "mptbase.h"
  61. #include "mptscsih.h"
  62. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  63. #define my_NAME "Fusion MPT FC Host driver"
  64. #define my_VERSION MPT_LINUX_VERSION_COMMON
  65. #define MYNAM "mptfc"
  66. MODULE_AUTHOR(MODULEAUTHOR);
  67. MODULE_DESCRIPTION(my_NAME);
  68. MODULE_LICENSE("GPL");
  69. MODULE_VERSION(my_VERSION);
  70. /* Command line args */
  71. #define MPTFC_DEV_LOSS_TMO (60)
  72. static int mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO; /* reasonable default */
  73. module_param(mptfc_dev_loss_tmo, int, 0);
  74. MODULE_PARM_DESC(mptfc_dev_loss_tmo, " Initial time the driver programs the "
  75. " transport to wait for an rport to "
  76. " return following a device loss event."
  77. " Default=60.");
  78. /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
  79. #define MPTFC_MAX_LUN (16895)
  80. static int max_lun = MPTFC_MAX_LUN;
  81. module_param(max_lun, int, 0);
  82. MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
  83. static u8 mptfcDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
  84. static u8 mptfcTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
  85. static u8 mptfcInternalCtx = MPT_MAX_PROTOCOL_DRIVERS;
  86. static int mptfc_target_alloc(struct scsi_target *starget);
  87. static int mptfc_sdev_init(struct scsi_device *sdev);
  88. static enum scsi_qc_status mptfc_qcmd(struct Scsi_Host *shost,
  89. struct scsi_cmnd *SCpnt);
  90. static void mptfc_target_destroy(struct scsi_target *starget);
  91. static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout);
  92. static void mptfc_remove(struct pci_dev *pdev);
  93. static int mptfc_abort(struct scsi_cmnd *SCpnt);
  94. static int mptfc_dev_reset(struct scsi_cmnd *SCpnt);
  95. static int mptfc_bus_reset(struct scsi_cmnd *SCpnt);
  96. static const struct scsi_host_template mptfc_driver_template = {
  97. .module = THIS_MODULE,
  98. .proc_name = "mptfc",
  99. .show_info = mptscsih_show_info,
  100. .name = "MPT FC Host",
  101. .info = mptscsih_info,
  102. .queuecommand = mptfc_qcmd,
  103. .target_alloc = mptfc_target_alloc,
  104. .sdev_init = mptfc_sdev_init,
  105. .sdev_configure = mptscsih_sdev_configure,
  106. .target_destroy = mptfc_target_destroy,
  107. .sdev_destroy = mptscsih_sdev_destroy,
  108. .change_queue_depth = mptscsih_change_queue_depth,
  109. .eh_timed_out = fc_eh_timed_out,
  110. .eh_abort_handler = mptfc_abort,
  111. .eh_device_reset_handler = mptfc_dev_reset,
  112. .eh_bus_reset_handler = mptfc_bus_reset,
  113. .eh_host_reset_handler = mptscsih_host_reset,
  114. .bios_param = mptscsih_bios_param,
  115. .can_queue = MPT_FC_CAN_QUEUE,
  116. .this_id = -1,
  117. .sg_tablesize = MPT_SCSI_SG_DEPTH,
  118. .max_sectors = 8192,
  119. .cmd_per_lun = 7,
  120. .dma_alignment = 511,
  121. .shost_groups = mptscsih_host_attr_groups,
  122. };
  123. /****************************************************************************
  124. * Supported hardware
  125. */
  126. static const struct pci_device_id mptfc_pci_table[] = {
  127. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC909,
  128. PCI_ANY_ID, PCI_ANY_ID },
  129. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919,
  130. PCI_ANY_ID, PCI_ANY_ID },
  131. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929,
  132. PCI_ANY_ID, PCI_ANY_ID },
  133. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919X,
  134. PCI_ANY_ID, PCI_ANY_ID },
  135. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929X,
  136. PCI_ANY_ID, PCI_ANY_ID },
  137. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC939X,
  138. PCI_ANY_ID, PCI_ANY_ID },
  139. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949X,
  140. PCI_ANY_ID, PCI_ANY_ID },
  141. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949E,
  142. PCI_ANY_ID, PCI_ANY_ID },
  143. { PCI_VENDOR_ID_BROCADE, MPI_MANUFACTPAGE_DEVICEID_FC949E,
  144. PCI_ANY_ID, PCI_ANY_ID },
  145. {0} /* Terminating entry */
  146. };
  147. MODULE_DEVICE_TABLE(pci, mptfc_pci_table);
  148. static struct scsi_transport_template *mptfc_transport_template = NULL;
  149. static struct fc_function_template mptfc_transport_functions = {
  150. .dd_fcrport_size = 8,
  151. .show_host_node_name = 1,
  152. .show_host_port_name = 1,
  153. .show_host_supported_classes = 1,
  154. .show_host_port_id = 1,
  155. .show_rport_supported_classes = 1,
  156. .show_starget_node_name = 1,
  157. .show_starget_port_name = 1,
  158. .show_starget_port_id = 1,
  159. .set_rport_dev_loss_tmo = mptfc_set_rport_loss_tmo,
  160. .show_rport_dev_loss_tmo = 1,
  161. .show_host_supported_speeds = 1,
  162. .show_host_maxframe_size = 1,
  163. .show_host_speed = 1,
  164. .show_host_fabric_name = 1,
  165. .show_host_port_type = 1,
  166. .show_host_port_state = 1,
  167. .show_host_symbolic_name = 1,
  168. };
  169. static int
  170. mptfc_block_error_handler(struct fc_rport *rport)
  171. {
  172. MPT_SCSI_HOST *hd;
  173. struct Scsi_Host *shost = rport_to_shost(rport);
  174. unsigned long flags;
  175. int ready;
  176. MPT_ADAPTER *ioc;
  177. int loops = 40; /* seconds */
  178. hd = shost_priv(shost);
  179. ioc = hd->ioc;
  180. spin_lock_irqsave(shost->host_lock, flags);
  181. while ((ready = fc_remote_port_chkready(rport) >> 16) == DID_IMM_RETRY
  182. || (loops > 0 && ioc->active == 0)) {
  183. spin_unlock_irqrestore(shost->host_lock, flags);
  184. dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
  185. "mptfc_block_error_handler.%d: %s, port status is "
  186. "%x, active flag %d, deferring recovery.\n",
  187. ioc->name, ioc->sh->host_no,
  188. dev_name(&rport->dev), ready, ioc->active));
  189. msleep(1000);
  190. spin_lock_irqsave(shost->host_lock, flags);
  191. loops --;
  192. }
  193. spin_unlock_irqrestore(shost->host_lock, flags);
  194. if (ready == DID_NO_CONNECT || ioc->active == 0) {
  195. dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
  196. "mpt_block_error_handler.%d: %s, failing recovery, "
  197. "port state %x, active %d.\n",
  198. ioc->name, ioc->sh->host_no,
  199. dev_name(&rport->dev), ready, ioc->active));
  200. return FAILED;
  201. }
  202. return SUCCESS;
  203. }
  204. static int
  205. mptfc_abort(struct scsi_cmnd *SCpnt)
  206. {
  207. struct Scsi_Host *shost = SCpnt->device->host;
  208. struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
  209. MPT_SCSI_HOST __maybe_unused *hd = shost_priv(shost);
  210. int rtn;
  211. rtn = mptfc_block_error_handler(rport);
  212. if (rtn == SUCCESS) {
  213. dfcprintk (hd->ioc, printk(MYIOC_s_DEBUG_FMT
  214. "%s.%d: %d:%llu, executing recovery.\n", __func__,
  215. hd->ioc->name, shost->host_no,
  216. SCpnt->device->id, SCpnt->device->lun));
  217. rtn = mptscsih_abort(SCpnt);
  218. }
  219. return rtn;
  220. }
  221. static int
  222. mptfc_dev_reset(struct scsi_cmnd *SCpnt)
  223. {
  224. struct Scsi_Host *shost = SCpnt->device->host;
  225. struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
  226. MPT_SCSI_HOST __maybe_unused *hd = shost_priv(shost);
  227. int rtn;
  228. rtn = mptfc_block_error_handler(rport);
  229. if (rtn == SUCCESS) {
  230. dfcprintk (hd->ioc, printk(MYIOC_s_DEBUG_FMT
  231. "%s.%d: %d:%llu, executing recovery.\n", __func__,
  232. hd->ioc->name, shost->host_no,
  233. SCpnt->device->id, SCpnt->device->lun));
  234. rtn = mptscsih_dev_reset(SCpnt);
  235. }
  236. return rtn;
  237. }
  238. static int
  239. mptfc_bus_reset(struct scsi_cmnd *SCpnt)
  240. {
  241. struct Scsi_Host *shost = SCpnt->device->host;
  242. MPT_SCSI_HOST __maybe_unused *hd = shost_priv(shost);
  243. int channel = SCpnt->device->channel;
  244. struct mptfc_rport_info *ri;
  245. int rtn = FAILED;
  246. list_for_each_entry(ri, &hd->ioc->fc_rports, list) {
  247. if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
  248. VirtTarget *vtarget = ri->starget->hostdata;
  249. if (!vtarget || vtarget->channel != channel)
  250. continue;
  251. rtn = fc_block_rport(ri->rport);
  252. if (rtn != 0)
  253. break;
  254. }
  255. }
  256. if (rtn == 0) {
  257. dfcprintk (hd->ioc, printk(MYIOC_s_DEBUG_FMT
  258. "%s.%d: %d:%llu, executing recovery.\n", __func__,
  259. hd->ioc->name, shost->host_no,
  260. SCpnt->device->id, SCpnt->device->lun));
  261. rtn = mptscsih_bus_reset(SCpnt);
  262. }
  263. return rtn;
  264. }
  265. static void
  266. mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  267. {
  268. if (timeout > 0)
  269. rport->dev_loss_tmo = timeout;
  270. else
  271. rport->dev_loss_tmo = mptfc_dev_loss_tmo;
  272. }
  273. static int
  274. mptfc_FcDevPage0_cmp_func(const void *a, const void *b)
  275. {
  276. FCDevicePage0_t **aa = (FCDevicePage0_t **)a;
  277. FCDevicePage0_t **bb = (FCDevicePage0_t **)b;
  278. if ((*aa)->CurrentBus == (*bb)->CurrentBus) {
  279. if ((*aa)->CurrentTargetID == (*bb)->CurrentTargetID)
  280. return 0;
  281. if ((*aa)->CurrentTargetID < (*bb)->CurrentTargetID)
  282. return -1;
  283. return 1;
  284. }
  285. if ((*aa)->CurrentBus < (*bb)->CurrentBus)
  286. return -1;
  287. return 1;
  288. }
  289. static int
  290. mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, int ioc_port,
  291. void(*func)(MPT_ADAPTER *ioc,int channel, FCDevicePage0_t *arg))
  292. {
  293. ConfigPageHeader_t hdr;
  294. CONFIGPARMS cfg;
  295. FCDevicePage0_t *ppage0_alloc, *fc;
  296. dma_addr_t page0_dma;
  297. int data_sz;
  298. int ii;
  299. FCDevicePage0_t *p0_array=NULL, *p_p0;
  300. FCDevicePage0_t **pp0_array=NULL, **p_pp0;
  301. int rc = -ENOMEM;
  302. U32 port_id = 0xffffff;
  303. int num_targ = 0;
  304. int max_bus = ioc->facts.MaxBuses;
  305. int max_targ;
  306. max_targ = (ioc->facts.MaxDevices == 0) ? 256 : ioc->facts.MaxDevices;
  307. data_sz = sizeof(FCDevicePage0_t) * max_bus * max_targ;
  308. p_p0 = p0_array = kzalloc(data_sz, GFP_KERNEL);
  309. if (!p0_array)
  310. goto out;
  311. data_sz = sizeof(FCDevicePage0_t *) * max_bus * max_targ;
  312. p_pp0 = pp0_array = kzalloc(data_sz, GFP_KERNEL);
  313. if (!pp0_array)
  314. goto out;
  315. do {
  316. /* Get FC Device Page 0 header */
  317. hdr.PageVersion = 0;
  318. hdr.PageLength = 0;
  319. hdr.PageNumber = 0;
  320. hdr.PageType = MPI_CONFIG_PAGETYPE_FC_DEVICE;
  321. cfg.cfghdr.hdr = &hdr;
  322. cfg.physAddr = -1;
  323. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  324. cfg.dir = 0;
  325. cfg.pageAddr = port_id;
  326. cfg.timeout = 0;
  327. if ((rc = mpt_config(ioc, &cfg)) != 0)
  328. break;
  329. if (hdr.PageLength <= 0)
  330. break;
  331. data_sz = hdr.PageLength * 4;
  332. ppage0_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz,
  333. &page0_dma, GFP_KERNEL);
  334. rc = -ENOMEM;
  335. if (!ppage0_alloc)
  336. break;
  337. cfg.physAddr = page0_dma;
  338. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  339. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  340. ppage0_alloc->PortIdentifier =
  341. le32_to_cpu(ppage0_alloc->PortIdentifier);
  342. ppage0_alloc->WWNN.Low =
  343. le32_to_cpu(ppage0_alloc->WWNN.Low);
  344. ppage0_alloc->WWNN.High =
  345. le32_to_cpu(ppage0_alloc->WWNN.High);
  346. ppage0_alloc->WWPN.Low =
  347. le32_to_cpu(ppage0_alloc->WWPN.Low);
  348. ppage0_alloc->WWPN.High =
  349. le32_to_cpu(ppage0_alloc->WWPN.High);
  350. ppage0_alloc->BBCredit =
  351. le16_to_cpu(ppage0_alloc->BBCredit);
  352. ppage0_alloc->MaxRxFrameSize =
  353. le16_to_cpu(ppage0_alloc->MaxRxFrameSize);
  354. port_id = ppage0_alloc->PortIdentifier;
  355. num_targ++;
  356. *p_p0 = *ppage0_alloc; /* save data */
  357. *p_pp0++ = p_p0++; /* save addr */
  358. }
  359. dma_free_coherent(&ioc->pcidev->dev, data_sz,
  360. ppage0_alloc, page0_dma);
  361. if (rc != 0)
  362. break;
  363. } while (port_id <= 0xff0000);
  364. if (num_targ) {
  365. /* sort array */
  366. if (num_targ > 1)
  367. sort (pp0_array, num_targ, sizeof(FCDevicePage0_t *),
  368. mptfc_FcDevPage0_cmp_func, NULL);
  369. /* call caller's func for each targ */
  370. for (ii = 0; ii < num_targ; ii++) {
  371. fc = *(pp0_array+ii);
  372. func(ioc, ioc_port, fc);
  373. }
  374. }
  375. out:
  376. kfree(pp0_array);
  377. kfree(p0_array);
  378. return rc;
  379. }
  380. static int
  381. mptfc_generate_rport_ids(FCDevicePage0_t *pg0, struct fc_rport_identifiers *rid)
  382. {
  383. /* not currently usable */
  384. if (pg0->Flags & (MPI_FC_DEVICE_PAGE0_FLAGS_PLOGI_INVALID |
  385. MPI_FC_DEVICE_PAGE0_FLAGS_PRLI_INVALID))
  386. return -1;
  387. if (!(pg0->Flags & MPI_FC_DEVICE_PAGE0_FLAGS_TARGETID_BUS_VALID))
  388. return -1;
  389. if (!(pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_TARGET))
  390. return -1;
  391. /*
  392. * board data structure already normalized to platform endianness
  393. * shifted to avoid unaligned access on 64 bit architecture
  394. */
  395. rid->node_name = ((u64)pg0->WWNN.High) << 32 | (u64)pg0->WWNN.Low;
  396. rid->port_name = ((u64)pg0->WWPN.High) << 32 | (u64)pg0->WWPN.Low;
  397. rid->port_id = pg0->PortIdentifier;
  398. rid->roles = FC_RPORT_ROLE_UNKNOWN;
  399. return 0;
  400. }
  401. static void
  402. mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
  403. {
  404. struct fc_rport_identifiers rport_ids;
  405. struct fc_rport *rport;
  406. struct mptfc_rport_info *ri;
  407. int new_ri = 1;
  408. u64 pn, nn;
  409. VirtTarget *vtarget;
  410. u32 roles = FC_RPORT_ROLE_UNKNOWN;
  411. if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0)
  412. return;
  413. roles |= FC_RPORT_ROLE_FCP_TARGET;
  414. if (pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_INITIATOR)
  415. roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  416. /* scan list looking for a match */
  417. list_for_each_entry(ri, &ioc->fc_rports, list) {
  418. pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
  419. if (pn == rport_ids.port_name) { /* match */
  420. list_move_tail(&ri->list, &ioc->fc_rports);
  421. new_ri = 0;
  422. break;
  423. }
  424. }
  425. if (new_ri) { /* allocate one */
  426. ri = kzalloc_obj(struct mptfc_rport_info);
  427. if (!ri)
  428. return;
  429. list_add_tail(&ri->list, &ioc->fc_rports);
  430. }
  431. ri->pg0 = *pg0; /* add/update pg0 data */
  432. ri->flags &= ~MPT_RPORT_INFO_FLAGS_MISSING;
  433. /* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */
  434. if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) {
  435. ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED;
  436. rport = fc_remote_port_add(ioc->sh, channel, &rport_ids);
  437. if (rport) {
  438. ri->rport = rport;
  439. if (new_ri) /* may have been reset by user */
  440. rport->dev_loss_tmo = mptfc_dev_loss_tmo;
  441. /*
  442. * if already mapped, remap here. If not mapped,
  443. * target_alloc will allocate vtarget and map,
  444. * sdev_init will fill in vdevice from vtarget.
  445. */
  446. if (ri->starget) {
  447. vtarget = ri->starget->hostdata;
  448. if (vtarget) {
  449. vtarget->id = pg0->CurrentTargetID;
  450. vtarget->channel = pg0->CurrentBus;
  451. vtarget->deleted = 0;
  452. }
  453. }
  454. *((struct mptfc_rport_info **)rport->dd_data) = ri;
  455. /* scan will be scheduled once rport becomes a target */
  456. fc_remote_port_rolechg(rport,roles);
  457. pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
  458. nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
  459. dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
  460. "mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, "
  461. "rport tid %d, tmo %d\n",
  462. ioc->name,
  463. ioc->sh->host_no,
  464. pg0->PortIdentifier,
  465. (unsigned long long)nn,
  466. (unsigned long long)pn,
  467. pg0->CurrentTargetID,
  468. ri->rport->scsi_target_id,
  469. ri->rport->dev_loss_tmo));
  470. } else {
  471. list_del(&ri->list);
  472. kfree(ri);
  473. ri = NULL;
  474. }
  475. }
  476. }
  477. /*
  478. * OS entry point to allow for host driver to free allocated memory
  479. * Called if no device present or device being unloaded
  480. */
  481. static void
  482. mptfc_target_destroy(struct scsi_target *starget)
  483. {
  484. struct fc_rport *rport;
  485. struct mptfc_rport_info *ri;
  486. rport = starget_to_rport(starget);
  487. if (rport) {
  488. ri = *((struct mptfc_rport_info **)rport->dd_data);
  489. if (ri) /* better be! */
  490. ri->starget = NULL;
  491. }
  492. kfree(starget->hostdata);
  493. starget->hostdata = NULL;
  494. }
  495. /*
  496. * OS entry point to allow host driver to alloc memory
  497. * for each scsi target. Called once per device the bus scan.
  498. * Return non-zero if allocation fails.
  499. */
  500. static int
  501. mptfc_target_alloc(struct scsi_target *starget)
  502. {
  503. VirtTarget *vtarget;
  504. struct fc_rport *rport;
  505. struct mptfc_rport_info *ri;
  506. int rc;
  507. vtarget = kzalloc_obj(VirtTarget);
  508. if (!vtarget)
  509. return -ENOMEM;
  510. starget->hostdata = vtarget;
  511. rc = -ENODEV;
  512. rport = starget_to_rport(starget);
  513. if (rport) {
  514. ri = *((struct mptfc_rport_info **)rport->dd_data);
  515. if (ri) { /* better be! */
  516. vtarget->id = ri->pg0.CurrentTargetID;
  517. vtarget->channel = ri->pg0.CurrentBus;
  518. ri->starget = starget;
  519. rc = 0;
  520. }
  521. }
  522. if (rc != 0) {
  523. kfree(vtarget);
  524. starget->hostdata = NULL;
  525. }
  526. return rc;
  527. }
  528. /*
  529. * mptfc_dump_lun_info
  530. * @ioc
  531. * @rport
  532. * @sdev
  533. *
  534. */
  535. static void
  536. mptfc_dump_lun_info(MPT_ADAPTER *ioc, struct fc_rport *rport, struct scsi_device *sdev,
  537. VirtTarget *vtarget)
  538. {
  539. u64 nn, pn;
  540. struct mptfc_rport_info *ri;
  541. ri = *((struct mptfc_rport_info **)rport->dd_data);
  542. pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
  543. nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
  544. dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
  545. "mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, "
  546. "CurrentTargetID %d, %x %llx %llx\n",
  547. ioc->name,
  548. sdev->host->host_no,
  549. vtarget->num_luns,
  550. sdev->id, ri->pg0.CurrentTargetID,
  551. ri->pg0.PortIdentifier,
  552. (unsigned long long)pn,
  553. (unsigned long long)nn));
  554. }
  555. /*
  556. * OS entry point to allow host driver to alloc memory
  557. * for each scsi device. Called once per device the bus scan.
  558. * Return non-zero if allocation fails.
  559. * Init memory once per LUN.
  560. */
  561. static int
  562. mptfc_sdev_init(struct scsi_device *sdev)
  563. {
  564. MPT_SCSI_HOST *hd;
  565. VirtTarget *vtarget;
  566. VirtDevice *vdevice;
  567. struct scsi_target *starget;
  568. struct fc_rport *rport;
  569. MPT_ADAPTER *ioc;
  570. starget = scsi_target(sdev);
  571. rport = starget_to_rport(starget);
  572. if (!rport || fc_remote_port_chkready(rport))
  573. return -ENXIO;
  574. hd = shost_priv(sdev->host);
  575. ioc = hd->ioc;
  576. vdevice = kzalloc_obj(VirtDevice);
  577. if (!vdevice) {
  578. printk(MYIOC_s_ERR_FMT "sdev_init kmalloc(%zd) FAILED!\n",
  579. ioc->name, sizeof(VirtDevice));
  580. return -ENOMEM;
  581. }
  582. sdev->hostdata = vdevice;
  583. vtarget = starget->hostdata;
  584. if (vtarget->num_luns == 0) {
  585. vtarget->ioc_id = ioc->id;
  586. vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
  587. }
  588. vdevice->vtarget = vtarget;
  589. vdevice->lun = sdev->lun;
  590. vtarget->num_luns++;
  591. mptfc_dump_lun_info(ioc, rport, sdev, vtarget);
  592. return 0;
  593. }
  594. static enum scsi_qc_status mptfc_qcmd(struct Scsi_Host *shost,
  595. struct scsi_cmnd *SCpnt)
  596. {
  597. struct mptfc_rport_info *ri;
  598. struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
  599. int err;
  600. VirtDevice *vdevice = SCpnt->device->hostdata;
  601. if (!vdevice || !vdevice->vtarget) {
  602. SCpnt->result = DID_NO_CONNECT << 16;
  603. scsi_done(SCpnt);
  604. return 0;
  605. }
  606. err = fc_remote_port_chkready(rport);
  607. if (unlikely(err)) {
  608. SCpnt->result = err;
  609. scsi_done(SCpnt);
  610. return 0;
  611. }
  612. /* dd_data is null until finished adding target */
  613. ri = *((struct mptfc_rport_info **)rport->dd_data);
  614. if (unlikely(!ri)) {
  615. SCpnt->result = DID_IMM_RETRY << 16;
  616. scsi_done(SCpnt);
  617. return 0;
  618. }
  619. return mptscsih_qcmd(SCpnt);
  620. }
  621. /*
  622. * mptfc_display_port_link_speed - displaying link speed
  623. * @ioc: Pointer to MPT_ADAPTER structure
  624. * @portnum: IOC Port number
  625. * @pp0dest: port page0 data payload
  626. *
  627. */
  628. static void
  629. mptfc_display_port_link_speed(MPT_ADAPTER *ioc, int portnum, FCPortPage0_t *pp0dest)
  630. {
  631. u8 old_speed, new_speed, state;
  632. char *old, *new;
  633. if (portnum >= 2)
  634. return;
  635. old_speed = ioc->fc_link_speed[portnum];
  636. new_speed = pp0dest->CurrentSpeed;
  637. state = pp0dest->PortState;
  638. if (state != MPI_FCPORTPAGE0_PORTSTATE_OFFLINE &&
  639. new_speed != MPI_FCPORTPAGE0_CURRENT_SPEED_UNKNOWN) {
  640. old = old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT ? "1 Gbps" :
  641. old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT ? "2 Gbps" :
  642. old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT ? "4 Gbps" :
  643. "Unknown";
  644. new = new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT ? "1 Gbps" :
  645. new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT ? "2 Gbps" :
  646. new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT ? "4 Gbps" :
  647. "Unknown";
  648. if (old_speed == 0)
  649. printk(MYIOC_s_NOTE_FMT
  650. "FC Link Established, Speed = %s\n",
  651. ioc->name, new);
  652. else if (old_speed != new_speed)
  653. printk(MYIOC_s_WARN_FMT
  654. "FC Link Speed Change, Old Speed = %s, New Speed = %s\n",
  655. ioc->name, old, new);
  656. ioc->fc_link_speed[portnum] = new_speed;
  657. }
  658. }
  659. /*
  660. * mptfc_GetFcPortPage0 - Fetch FCPort config Page0.
  661. * @ioc: Pointer to MPT_ADAPTER structure
  662. * @portnum: IOC Port number
  663. *
  664. * Return: 0 for success
  665. * -ENOMEM if no memory available
  666. * -EPERM if not allowed due to ISR context
  667. * -EAGAIN if no msg frames currently available
  668. * -EFAULT for non-successful reply or no reply (timeout)
  669. * -EINVAL portnum arg out of range (hardwired to two elements)
  670. */
  671. static int
  672. mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
  673. {
  674. ConfigPageHeader_t hdr;
  675. CONFIGPARMS cfg;
  676. FCPortPage0_t *ppage0_alloc;
  677. FCPortPage0_t *pp0dest;
  678. dma_addr_t page0_dma;
  679. int data_sz;
  680. int copy_sz;
  681. int rc;
  682. int count = 400;
  683. if (portnum > 1)
  684. return -EINVAL;
  685. /* Get FCPort Page 0 header */
  686. hdr.PageVersion = 0;
  687. hdr.PageLength = 0;
  688. hdr.PageNumber = 0;
  689. hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
  690. cfg.cfghdr.hdr = &hdr;
  691. cfg.physAddr = -1;
  692. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  693. cfg.dir = 0;
  694. cfg.pageAddr = portnum;
  695. cfg.timeout = 0;
  696. if ((rc = mpt_config(ioc, &cfg)) != 0)
  697. return rc;
  698. if (hdr.PageLength == 0)
  699. return 0;
  700. data_sz = hdr.PageLength * 4;
  701. rc = -ENOMEM;
  702. ppage0_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz,
  703. &page0_dma, GFP_KERNEL);
  704. if (ppage0_alloc) {
  705. try_again:
  706. memset((u8 *)ppage0_alloc, 0, data_sz);
  707. cfg.physAddr = page0_dma;
  708. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  709. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  710. /* save the data */
  711. pp0dest = &ioc->fc_port_page0[portnum];
  712. copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
  713. memcpy(pp0dest, ppage0_alloc, copy_sz);
  714. /*
  715. * Normalize endianness of structure data,
  716. * by byte-swapping all > 1 byte fields!
  717. */
  718. pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
  719. pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
  720. pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
  721. pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
  722. pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
  723. pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
  724. pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
  725. pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
  726. pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
  727. pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
  728. pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
  729. pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
  730. pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
  731. pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
  732. pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
  733. pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
  734. /*
  735. * if still doing discovery,
  736. * hang loose a while until finished
  737. */
  738. if ((pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) ||
  739. (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE &&
  740. (pp0dest->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_TYPE_MASK)
  741. == MPI_FCPORTPAGE0_FLAGS_ATTACH_NO_INIT)) {
  742. if (count-- > 0) {
  743. msleep(100);
  744. goto try_again;
  745. }
  746. printk(MYIOC_s_INFO_FMT "Firmware discovery not"
  747. " complete.\n",
  748. ioc->name);
  749. }
  750. mptfc_display_port_link_speed(ioc, portnum, pp0dest);
  751. }
  752. dma_free_coherent(&ioc->pcidev->dev, data_sz, ppage0_alloc,
  753. page0_dma);
  754. }
  755. return rc;
  756. }
  757. static int
  758. mptfc_WriteFcPortPage1(MPT_ADAPTER *ioc, int portnum)
  759. {
  760. ConfigPageHeader_t hdr;
  761. CONFIGPARMS cfg;
  762. int rc;
  763. if (portnum > 1)
  764. return -EINVAL;
  765. if (!(ioc->fc_data.fc_port_page1[portnum].data))
  766. return -EINVAL;
  767. /* get fcport page 1 header */
  768. hdr.PageVersion = 0;
  769. hdr.PageLength = 0;
  770. hdr.PageNumber = 1;
  771. hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
  772. cfg.cfghdr.hdr = &hdr;
  773. cfg.physAddr = -1;
  774. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  775. cfg.dir = 0;
  776. cfg.pageAddr = portnum;
  777. cfg.timeout = 0;
  778. if ((rc = mpt_config(ioc, &cfg)) != 0)
  779. return rc;
  780. if (hdr.PageLength == 0)
  781. return -ENODEV;
  782. if (hdr.PageLength*4 != ioc->fc_data.fc_port_page1[portnum].pg_sz)
  783. return -EINVAL;
  784. cfg.physAddr = ioc->fc_data.fc_port_page1[portnum].dma;
  785. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  786. cfg.dir = 1;
  787. rc = mpt_config(ioc, &cfg);
  788. return rc;
  789. }
  790. static int
  791. mptfc_GetFcPortPage1(MPT_ADAPTER *ioc, int portnum)
  792. {
  793. ConfigPageHeader_t hdr;
  794. CONFIGPARMS cfg;
  795. FCPortPage1_t *page1_alloc;
  796. dma_addr_t page1_dma;
  797. int data_sz;
  798. int rc;
  799. if (portnum > 1)
  800. return -EINVAL;
  801. /* get fcport page 1 header */
  802. hdr.PageVersion = 0;
  803. hdr.PageLength = 0;
  804. hdr.PageNumber = 1;
  805. hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
  806. cfg.cfghdr.hdr = &hdr;
  807. cfg.physAddr = -1;
  808. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  809. cfg.dir = 0;
  810. cfg.pageAddr = portnum;
  811. cfg.timeout = 0;
  812. if ((rc = mpt_config(ioc, &cfg)) != 0)
  813. return rc;
  814. if (hdr.PageLength == 0)
  815. return -ENODEV;
  816. start_over:
  817. if (ioc->fc_data.fc_port_page1[portnum].data == NULL) {
  818. data_sz = hdr.PageLength * 4;
  819. if (data_sz < sizeof(FCPortPage1_t))
  820. data_sz = sizeof(FCPortPage1_t);
  821. page1_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz,
  822. &page1_dma, GFP_KERNEL);
  823. if (!page1_alloc)
  824. return -ENOMEM;
  825. }
  826. else {
  827. page1_alloc = ioc->fc_data.fc_port_page1[portnum].data;
  828. page1_dma = ioc->fc_data.fc_port_page1[portnum].dma;
  829. data_sz = ioc->fc_data.fc_port_page1[portnum].pg_sz;
  830. if (hdr.PageLength * 4 > data_sz) {
  831. ioc->fc_data.fc_port_page1[portnum].data = NULL;
  832. dma_free_coherent(&ioc->pcidev->dev, data_sz,
  833. page1_alloc, page1_dma);
  834. goto start_over;
  835. }
  836. }
  837. cfg.physAddr = page1_dma;
  838. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  839. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  840. ioc->fc_data.fc_port_page1[portnum].data = page1_alloc;
  841. ioc->fc_data.fc_port_page1[portnum].pg_sz = data_sz;
  842. ioc->fc_data.fc_port_page1[portnum].dma = page1_dma;
  843. }
  844. else {
  845. ioc->fc_data.fc_port_page1[portnum].data = NULL;
  846. dma_free_coherent(&ioc->pcidev->dev, data_sz, page1_alloc,
  847. page1_dma);
  848. }
  849. return rc;
  850. }
  851. static void
  852. mptfc_SetFcPortPage1_defaults(MPT_ADAPTER *ioc)
  853. {
  854. int ii;
  855. FCPortPage1_t *pp1;
  856. #define MPTFC_FW_DEVICE_TIMEOUT (1)
  857. #define MPTFC_FW_IO_PEND_TIMEOUT (1)
  858. #define ON_FLAGS (MPI_FCPORTPAGE1_FLAGS_IMMEDIATE_ERROR_REPLY)
  859. #define OFF_FLAGS (MPI_FCPORTPAGE1_FLAGS_VERBOSE_RESCAN_EVENTS)
  860. for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
  861. if (mptfc_GetFcPortPage1(ioc, ii) != 0)
  862. continue;
  863. pp1 = ioc->fc_data.fc_port_page1[ii].data;
  864. if ((pp1->InitiatorDeviceTimeout == MPTFC_FW_DEVICE_TIMEOUT)
  865. && (pp1->InitiatorIoPendTimeout == MPTFC_FW_IO_PEND_TIMEOUT)
  866. && ((pp1->Flags & ON_FLAGS) == ON_FLAGS)
  867. && ((pp1->Flags & OFF_FLAGS) == 0))
  868. continue;
  869. pp1->InitiatorDeviceTimeout = MPTFC_FW_DEVICE_TIMEOUT;
  870. pp1->InitiatorIoPendTimeout = MPTFC_FW_IO_PEND_TIMEOUT;
  871. pp1->Flags &= ~OFF_FLAGS;
  872. pp1->Flags |= ON_FLAGS;
  873. mptfc_WriteFcPortPage1(ioc, ii);
  874. }
  875. }
  876. static void
  877. mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum)
  878. {
  879. unsigned class = 0;
  880. unsigned cos = 0;
  881. unsigned speed;
  882. unsigned port_type;
  883. unsigned port_state;
  884. FCPortPage0_t *pp0;
  885. struct Scsi_Host *sh;
  886. char *sn;
  887. /* don't know what to do as only one scsi (fc) host was allocated */
  888. if (portnum != 0)
  889. return;
  890. pp0 = &ioc->fc_port_page0[portnum];
  891. sh = ioc->sh;
  892. sn = fc_host_symbolic_name(sh);
  893. snprintf(sn, FC_SYMBOLIC_NAME_SIZE, "%s %s%08xh",
  894. ioc->prod_name,
  895. MPT_FW_REV_MAGIC_ID_STRING,
  896. ioc->facts.FWVersion.Word);
  897. fc_host_tgtid_bind_type(sh) = FC_TGTID_BIND_BY_WWPN;
  898. fc_host_maxframe_size(sh) = pp0->MaxFrameSize;
  899. fc_host_node_name(sh) =
  900. (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
  901. fc_host_port_name(sh) =
  902. (u64)pp0->WWPN.High << 32 | (u64)pp0->WWPN.Low;
  903. fc_host_port_id(sh) = pp0->PortIdentifier;
  904. class = pp0->SupportedServiceClass;
  905. if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1)
  906. cos |= FC_COS_CLASS1;
  907. if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2)
  908. cos |= FC_COS_CLASS2;
  909. if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3)
  910. cos |= FC_COS_CLASS3;
  911. fc_host_supported_classes(sh) = cos;
  912. if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT)
  913. speed = FC_PORTSPEED_1GBIT;
  914. else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT)
  915. speed = FC_PORTSPEED_2GBIT;
  916. else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT)
  917. speed = FC_PORTSPEED_4GBIT;
  918. else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_10GBIT)
  919. speed = FC_PORTSPEED_10GBIT;
  920. else
  921. speed = FC_PORTSPEED_UNKNOWN;
  922. fc_host_speed(sh) = speed;
  923. speed = 0;
  924. if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_1GBIT_SPEED)
  925. speed |= FC_PORTSPEED_1GBIT;
  926. if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_2GBIT_SPEED)
  927. speed |= FC_PORTSPEED_2GBIT;
  928. if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_4GBIT_SPEED)
  929. speed |= FC_PORTSPEED_4GBIT;
  930. if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_10GBIT_SPEED)
  931. speed |= FC_PORTSPEED_10GBIT;
  932. fc_host_supported_speeds(sh) = speed;
  933. port_state = FC_PORTSTATE_UNKNOWN;
  934. if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE)
  935. port_state = FC_PORTSTATE_ONLINE;
  936. else if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_OFFLINE)
  937. port_state = FC_PORTSTATE_LINKDOWN;
  938. fc_host_port_state(sh) = port_state;
  939. port_type = FC_PORTTYPE_UNKNOWN;
  940. if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_POINT_TO_POINT)
  941. port_type = FC_PORTTYPE_PTP;
  942. else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PRIVATE_LOOP)
  943. port_type = FC_PORTTYPE_LPORT;
  944. else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PUBLIC_LOOP)
  945. port_type = FC_PORTTYPE_NLPORT;
  946. else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_FABRIC_DIRECT)
  947. port_type = FC_PORTTYPE_NPORT;
  948. fc_host_port_type(sh) = port_type;
  949. fc_host_fabric_name(sh) =
  950. (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_FABRIC_WWN_VALID) ?
  951. (u64) pp0->FabricWWNN.High << 32 | (u64) pp0->FabricWWPN.Low :
  952. (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
  953. }
  954. static void
  955. mptfc_link_status_change(struct work_struct *work)
  956. {
  957. MPT_ADAPTER *ioc =
  958. container_of(work, MPT_ADAPTER, fc_rescan_work);
  959. int ii;
  960. for (ii=0; ii < ioc->facts.NumberOfPorts; ii++)
  961. (void) mptfc_GetFcPortPage0(ioc, ii);
  962. }
  963. static void
  964. mptfc_setup_reset(struct work_struct *work)
  965. {
  966. MPT_ADAPTER *ioc =
  967. container_of(work, MPT_ADAPTER, fc_setup_reset_work);
  968. u64 pn;
  969. struct mptfc_rport_info *ri;
  970. struct scsi_target *starget;
  971. VirtTarget *vtarget;
  972. /* reset about to happen, delete (block) all rports */
  973. list_for_each_entry(ri, &ioc->fc_rports, list) {
  974. if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
  975. ri->flags &= ~MPT_RPORT_INFO_FLAGS_REGISTERED;
  976. fc_remote_port_delete(ri->rport); /* won't sleep */
  977. ri->rport = NULL;
  978. starget = ri->starget;
  979. if (starget) {
  980. vtarget = starget->hostdata;
  981. if (vtarget)
  982. vtarget->deleted = 1;
  983. }
  984. pn = (u64)ri->pg0.WWPN.High << 32 |
  985. (u64)ri->pg0.WWPN.Low;
  986. dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
  987. "mptfc_setup_reset.%d: %llx deleted\n",
  988. ioc->name,
  989. ioc->sh->host_no,
  990. (unsigned long long)pn));
  991. }
  992. }
  993. }
  994. static void
  995. mptfc_rescan_devices(struct work_struct *work)
  996. {
  997. MPT_ADAPTER *ioc =
  998. container_of(work, MPT_ADAPTER, fc_rescan_work);
  999. int ii;
  1000. u64 pn;
  1001. struct mptfc_rport_info *ri;
  1002. struct scsi_target *starget;
  1003. VirtTarget *vtarget;
  1004. /* start by tagging all ports as missing */
  1005. list_for_each_entry(ri, &ioc->fc_rports, list) {
  1006. if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
  1007. ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
  1008. }
  1009. }
  1010. /*
  1011. * now rescan devices known to adapter,
  1012. * will reregister existing rports
  1013. */
  1014. for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
  1015. (void) mptfc_GetFcPortPage0(ioc, ii);
  1016. mptfc_init_host_attr(ioc, ii); /* refresh */
  1017. mptfc_GetFcDevPage0(ioc, ii, mptfc_register_dev);
  1018. }
  1019. /* delete devices still missing */
  1020. list_for_each_entry(ri, &ioc->fc_rports, list) {
  1021. /* if newly missing, delete it */
  1022. if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) {
  1023. ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED|
  1024. MPT_RPORT_INFO_FLAGS_MISSING);
  1025. fc_remote_port_delete(ri->rport); /* won't sleep */
  1026. ri->rport = NULL;
  1027. starget = ri->starget;
  1028. if (starget) {
  1029. vtarget = starget->hostdata;
  1030. if (vtarget)
  1031. vtarget->deleted = 1;
  1032. }
  1033. pn = (u64)ri->pg0.WWPN.High << 32 |
  1034. (u64)ri->pg0.WWPN.Low;
  1035. dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
  1036. "mptfc_rescan.%d: %llx deleted\n",
  1037. ioc->name,
  1038. ioc->sh->host_no,
  1039. (unsigned long long)pn));
  1040. }
  1041. }
  1042. }
  1043. static int
  1044. mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1045. {
  1046. struct Scsi_Host *sh;
  1047. MPT_SCSI_HOST *hd;
  1048. MPT_ADAPTER *ioc;
  1049. unsigned long flags;
  1050. int ii;
  1051. int numSGE = 0;
  1052. int scale;
  1053. int ioc_cap;
  1054. int error=0;
  1055. int r;
  1056. if ((r = mpt_attach(pdev,id)) != 0)
  1057. return r;
  1058. ioc = pci_get_drvdata(pdev);
  1059. ioc->DoneCtx = mptfcDoneCtx;
  1060. ioc->TaskCtx = mptfcTaskCtx;
  1061. ioc->InternalCtx = mptfcInternalCtx;
  1062. /* Added sanity check on readiness of the MPT adapter.
  1063. */
  1064. if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
  1065. printk(MYIOC_s_WARN_FMT
  1066. "Skipping because it's not operational!\n",
  1067. ioc->name);
  1068. error = -ENODEV;
  1069. goto out_mptfc_probe;
  1070. }
  1071. if (!ioc->active) {
  1072. printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
  1073. ioc->name);
  1074. error = -ENODEV;
  1075. goto out_mptfc_probe;
  1076. }
  1077. /* Sanity check - ensure at least 1 port is INITIATOR capable
  1078. */
  1079. ioc_cap = 0;
  1080. for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
  1081. if (ioc->pfacts[ii].ProtocolFlags &
  1082. MPI_PORTFACTS_PROTOCOL_INITIATOR)
  1083. ioc_cap ++;
  1084. }
  1085. if (!ioc_cap) {
  1086. printk(MYIOC_s_WARN_FMT
  1087. "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
  1088. ioc->name, ioc);
  1089. return 0;
  1090. }
  1091. sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
  1092. if (!sh) {
  1093. printk(MYIOC_s_WARN_FMT
  1094. "Unable to register controller with SCSI subsystem\n",
  1095. ioc->name);
  1096. error = -1;
  1097. goto out_mptfc_probe;
  1098. }
  1099. spin_lock_init(&ioc->fc_rescan_work_lock);
  1100. INIT_WORK(&ioc->fc_rescan_work, mptfc_rescan_devices);
  1101. INIT_WORK(&ioc->fc_setup_reset_work, mptfc_setup_reset);
  1102. INIT_WORK(&ioc->fc_lsc_work, mptfc_link_status_change);
  1103. spin_lock_irqsave(&ioc->FreeQlock, flags);
  1104. /* Attach the SCSI Host to the IOC structure
  1105. */
  1106. ioc->sh = sh;
  1107. sh->io_port = 0;
  1108. sh->n_io_port = 0;
  1109. sh->irq = 0;
  1110. /* set 16 byte cdb's */
  1111. sh->max_cmd_len = 16;
  1112. sh->max_id = ioc->pfacts->MaxDevices;
  1113. sh->max_lun = max_lun;
  1114. /* Required entry.
  1115. */
  1116. sh->unique_id = ioc->id;
  1117. /* Verify that we won't exceed the maximum
  1118. * number of chain buffers
  1119. * We can optimize: ZZ = req_sz/sizeof(SGE)
  1120. * For 32bit SGE's:
  1121. * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
  1122. * + (req_sz - 64)/sizeof(SGE)
  1123. * A slightly different algorithm is required for
  1124. * 64bit SGEs.
  1125. */
  1126. scale = ioc->req_sz/ioc->SGE_size;
  1127. if (ioc->sg_addr_size == sizeof(u64)) {
  1128. numSGE = (scale - 1) *
  1129. (ioc->facts.MaxChainDepth-1) + scale +
  1130. (ioc->req_sz - 60) / ioc->SGE_size;
  1131. } else {
  1132. numSGE = 1 + (scale - 1) *
  1133. (ioc->facts.MaxChainDepth-1) + scale +
  1134. (ioc->req_sz - 64) / ioc->SGE_size;
  1135. }
  1136. if (numSGE < sh->sg_tablesize) {
  1137. /* Reset this value */
  1138. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1139. "Resetting sg_tablesize to %d from %d\n",
  1140. ioc->name, numSGE, sh->sg_tablesize));
  1141. sh->sg_tablesize = numSGE;
  1142. }
  1143. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  1144. hd = shost_priv(sh);
  1145. hd->ioc = ioc;
  1146. /* SCSI needs scsi_cmnd lookup table!
  1147. * (with size equal to req_depth*PtrSz!)
  1148. */
  1149. ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_KERNEL);
  1150. if (!ioc->ScsiLookup) {
  1151. error = -ENOMEM;
  1152. goto out_mptfc_probe;
  1153. }
  1154. spin_lock_init(&ioc->scsi_lookup_lock);
  1155. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
  1156. ioc->name, ioc->ScsiLookup));
  1157. hd->last_queue_full = 0;
  1158. sh->transportt = mptfc_transport_template;
  1159. error = scsi_add_host (sh, &ioc->pcidev->dev);
  1160. if(error) {
  1161. dprintk(ioc, printk(MYIOC_s_ERR_FMT
  1162. "scsi_add_host failed\n", ioc->name));
  1163. goto out_mptfc_probe;
  1164. }
  1165. /* initialize workqueue */
  1166. ioc->fc_rescan_work_q = alloc_ordered_workqueue(
  1167. "mptfc_wq_%d", WQ_MEM_RECLAIM, sh->host_no);
  1168. if (!ioc->fc_rescan_work_q) {
  1169. error = -ENOMEM;
  1170. goto out_mptfc_host;
  1171. }
  1172. /*
  1173. * Pre-fetch FC port WWN and stuff...
  1174. * (FCPortPage0_t stuff)
  1175. */
  1176. for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
  1177. (void) mptfc_GetFcPortPage0(ioc, ii);
  1178. }
  1179. mptfc_SetFcPortPage1_defaults(ioc);
  1180. /*
  1181. * scan for rports -
  1182. * by doing it via the workqueue, some locking is eliminated
  1183. */
  1184. queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work);
  1185. flush_workqueue(ioc->fc_rescan_work_q);
  1186. return 0;
  1187. out_mptfc_host:
  1188. scsi_remove_host(sh);
  1189. out_mptfc_probe:
  1190. mptscsih_remove(pdev);
  1191. return error;
  1192. }
  1193. static struct pci_driver mptfc_driver = {
  1194. .name = "mptfc",
  1195. .id_table = mptfc_pci_table,
  1196. .probe = mptfc_probe,
  1197. .remove = mptfc_remove,
  1198. .shutdown = mptscsih_shutdown,
  1199. #ifdef CONFIG_PM
  1200. .suspend = mptscsih_suspend,
  1201. .resume = mptscsih_resume,
  1202. #endif
  1203. };
  1204. static int
  1205. mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
  1206. {
  1207. u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
  1208. unsigned long flags;
  1209. int rc=1;
  1210. if (ioc->bus_type != FC)
  1211. return 0;
  1212. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
  1213. ioc->name, event));
  1214. if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL)
  1215. return 1;
  1216. switch (event) {
  1217. case MPI_EVENT_RESCAN:
  1218. spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
  1219. if (ioc->fc_rescan_work_q) {
  1220. queue_work(ioc->fc_rescan_work_q,
  1221. &ioc->fc_rescan_work);
  1222. }
  1223. spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
  1224. break;
  1225. case MPI_EVENT_LINK_STATUS_CHANGE:
  1226. spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
  1227. if (ioc->fc_rescan_work_q) {
  1228. queue_work(ioc->fc_rescan_work_q,
  1229. &ioc->fc_lsc_work);
  1230. }
  1231. spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
  1232. break;
  1233. default:
  1234. rc = mptscsih_event_process(ioc,pEvReply);
  1235. break;
  1236. }
  1237. return rc;
  1238. }
  1239. static int
  1240. mptfc_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  1241. {
  1242. int rc;
  1243. unsigned long flags;
  1244. rc = mptscsih_ioc_reset(ioc,reset_phase);
  1245. if ((ioc->bus_type != FC) || (!rc))
  1246. return rc;
  1247. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1248. ": IOC %s_reset routed to FC host driver!\n",ioc->name,
  1249. reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
  1250. reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
  1251. if (reset_phase == MPT_IOC_SETUP_RESET) {
  1252. spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
  1253. if (ioc->fc_rescan_work_q) {
  1254. queue_work(ioc->fc_rescan_work_q,
  1255. &ioc->fc_setup_reset_work);
  1256. }
  1257. spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
  1258. }
  1259. else if (reset_phase == MPT_IOC_PRE_RESET) {
  1260. }
  1261. else { /* MPT_IOC_POST_RESET */
  1262. mptfc_SetFcPortPage1_defaults(ioc);
  1263. spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
  1264. if (ioc->fc_rescan_work_q) {
  1265. queue_work(ioc->fc_rescan_work_q,
  1266. &ioc->fc_rescan_work);
  1267. }
  1268. spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
  1269. }
  1270. return 1;
  1271. }
  1272. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1273. /**
  1274. * mptfc_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer.
  1275. *
  1276. * Returns 0 for success, non-zero for failure.
  1277. */
  1278. static int __init
  1279. mptfc_init(void)
  1280. {
  1281. int error;
  1282. show_mptmod_ver(my_NAME, my_VERSION);
  1283. /* sanity check module parameters */
  1284. if (mptfc_dev_loss_tmo <= 0)
  1285. mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO;
  1286. mptfc_transport_template =
  1287. fc_attach_transport(&mptfc_transport_functions);
  1288. if (!mptfc_transport_template)
  1289. return -ENODEV;
  1290. mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER,
  1291. "mptscsih_scandv_complete");
  1292. mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER,
  1293. "mptscsih_scandv_complete");
  1294. mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER,
  1295. "mptscsih_scandv_complete");
  1296. mpt_event_register(mptfcDoneCtx, mptfc_event_process);
  1297. mpt_reset_register(mptfcDoneCtx, mptfc_ioc_reset);
  1298. error = pci_register_driver(&mptfc_driver);
  1299. if (error)
  1300. fc_release_transport(mptfc_transport_template);
  1301. return error;
  1302. }
  1303. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1304. /**
  1305. * mptfc_remove - Remove fc infrastructure for devices
  1306. * @pdev: Pointer to pci_dev structure
  1307. *
  1308. */
  1309. static void mptfc_remove(struct pci_dev *pdev)
  1310. {
  1311. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1312. struct mptfc_rport_info *p, *n;
  1313. struct workqueue_struct *work_q;
  1314. unsigned long flags;
  1315. int ii;
  1316. /* destroy workqueue */
  1317. if ((work_q=ioc->fc_rescan_work_q)) {
  1318. spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
  1319. ioc->fc_rescan_work_q = NULL;
  1320. spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
  1321. destroy_workqueue(work_q);
  1322. }
  1323. fc_remove_host(ioc->sh);
  1324. list_for_each_entry_safe(p, n, &ioc->fc_rports, list) {
  1325. list_del(&p->list);
  1326. kfree(p);
  1327. }
  1328. for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
  1329. if (ioc->fc_data.fc_port_page1[ii].data) {
  1330. dma_free_coherent(&ioc->pcidev->dev,
  1331. ioc->fc_data.fc_port_page1[ii].pg_sz,
  1332. ioc->fc_data.fc_port_page1[ii].data,
  1333. ioc->fc_data.fc_port_page1[ii].dma);
  1334. ioc->fc_data.fc_port_page1[ii].data = NULL;
  1335. }
  1336. }
  1337. scsi_remove_host(ioc->sh);
  1338. mptscsih_remove(pdev);
  1339. }
  1340. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1341. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1342. /**
  1343. * mptfc_exit - Unregisters MPT adapter(s)
  1344. *
  1345. */
  1346. static void __exit
  1347. mptfc_exit(void)
  1348. {
  1349. pci_unregister_driver(&mptfc_driver);
  1350. fc_release_transport(mptfc_transport_template);
  1351. mpt_reset_deregister(mptfcDoneCtx);
  1352. mpt_event_deregister(mptfcDoneCtx);
  1353. mpt_deregister(mptfcInternalCtx);
  1354. mpt_deregister(mptfcTaskCtx);
  1355. mpt_deregister(mptfcDoneCtx);
  1356. }
  1357. module_init(mptfc_init);
  1358. module_exit(mptfc_exit);