mptfc.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /*
  2. * linux/drivers/message/fusion/mptfc.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 <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 "mptbase.h"
  60. #include "mptscsih.h"
  61. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  62. #define my_NAME "Fusion MPT FC Host driver"
  63. #define my_VERSION MPT_LINUX_VERSION_COMMON
  64. #define MYNAM "mptfc"
  65. MODULE_AUTHOR(MODULEAUTHOR);
  66. MODULE_DESCRIPTION(my_NAME);
  67. MODULE_LICENSE("GPL");
  68. /* Command line args */
  69. static int mpt_pq_filter = 0;
  70. module_param(mpt_pq_filter, int, 0);
  71. MODULE_PARM_DESC(mpt_pq_filter, " Enable peripheral qualifier filter: enable=1 (default=0)");
  72. static int mptfcDoneCtx = -1;
  73. static int mptfcTaskCtx = -1;
  74. static int mptfcInternalCtx = -1; /* Used only for internal commands */
  75. static struct scsi_host_template mptfc_driver_template = {
  76. .module = THIS_MODULE,
  77. .proc_name = "mptfc",
  78. .proc_info = mptscsih_proc_info,
  79. .name = "MPT FC Host",
  80. .info = mptscsih_info,
  81. .queuecommand = mptscsih_qcmd,
  82. .slave_alloc = mptscsih_slave_alloc,
  83. .slave_configure = mptscsih_slave_configure,
  84. .slave_destroy = mptscsih_slave_destroy,
  85. .change_queue_depth = mptscsih_change_queue_depth,
  86. .eh_abort_handler = mptscsih_abort,
  87. .eh_device_reset_handler = mptscsih_dev_reset,
  88. .eh_bus_reset_handler = mptscsih_bus_reset,
  89. .eh_host_reset_handler = mptscsih_host_reset,
  90. .bios_param = mptscsih_bios_param,
  91. .can_queue = MPT_FC_CAN_QUEUE,
  92. .this_id = -1,
  93. .sg_tablesize = MPT_SCSI_SG_DEPTH,
  94. .max_sectors = 8192,
  95. .cmd_per_lun = 7,
  96. .use_clustering = ENABLE_CLUSTERING,
  97. };
  98. /****************************************************************************
  99. * Supported hardware
  100. */
  101. static struct pci_device_id mptfc_pci_table[] = {
  102. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC909,
  103. PCI_ANY_ID, PCI_ANY_ID },
  104. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919,
  105. PCI_ANY_ID, PCI_ANY_ID },
  106. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929,
  107. PCI_ANY_ID, PCI_ANY_ID },
  108. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919X,
  109. PCI_ANY_ID, PCI_ANY_ID },
  110. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929X,
  111. PCI_ANY_ID, PCI_ANY_ID },
  112. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC939X,
  113. PCI_ANY_ID, PCI_ANY_ID },
  114. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC949X,
  115. PCI_ANY_ID, PCI_ANY_ID },
  116. {0} /* Terminating entry */
  117. };
  118. MODULE_DEVICE_TABLE(pci, mptfc_pci_table);
  119. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  120. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  121. /*
  122. * mptfc_probe - Installs scsi devices per bus.
  123. * @pdev: Pointer to pci_dev structure
  124. *
  125. * Returns 0 for success, non-zero for failure.
  126. *
  127. */
  128. static int
  129. mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  130. {
  131. struct Scsi_Host *sh;
  132. MPT_SCSI_HOST *hd;
  133. MPT_ADAPTER *ioc;
  134. unsigned long flags;
  135. int sz, ii;
  136. int numSGE = 0;
  137. int scale;
  138. int ioc_cap;
  139. u8 *mem;
  140. int error=0;
  141. int r;
  142. if ((r = mpt_attach(pdev,id)) != 0)
  143. return r;
  144. ioc = pci_get_drvdata(pdev);
  145. ioc->DoneCtx = mptfcDoneCtx;
  146. ioc->TaskCtx = mptfcTaskCtx;
  147. ioc->InternalCtx = mptfcInternalCtx;
  148. /* Added sanity check on readiness of the MPT adapter.
  149. */
  150. if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
  151. printk(MYIOC_s_WARN_FMT
  152. "Skipping because it's not operational!\n",
  153. ioc->name);
  154. error = -ENODEV;
  155. goto out_mptfc_probe;
  156. }
  157. if (!ioc->active) {
  158. printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
  159. ioc->name);
  160. error = -ENODEV;
  161. goto out_mptfc_probe;
  162. }
  163. /* Sanity check - ensure at least 1 port is INITIATOR capable
  164. */
  165. ioc_cap = 0;
  166. for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
  167. if (ioc->pfacts[ii].ProtocolFlags &
  168. MPI_PORTFACTS_PROTOCOL_INITIATOR)
  169. ioc_cap ++;
  170. }
  171. if (!ioc_cap) {
  172. printk(MYIOC_s_WARN_FMT
  173. "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
  174. ioc->name, ioc);
  175. return 0;
  176. }
  177. sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
  178. if (!sh) {
  179. printk(MYIOC_s_WARN_FMT
  180. "Unable to register controller with SCSI subsystem\n",
  181. ioc->name);
  182. error = -1;
  183. goto out_mptfc_probe;
  184. }
  185. spin_lock_irqsave(&ioc->FreeQlock, flags);
  186. /* Attach the SCSI Host to the IOC structure
  187. */
  188. ioc->sh = sh;
  189. sh->io_port = 0;
  190. sh->n_io_port = 0;
  191. sh->irq = 0;
  192. /* set 16 byte cdb's */
  193. sh->max_cmd_len = 16;
  194. sh->max_id = MPT_MAX_FC_DEVICES<256 ? MPT_MAX_FC_DEVICES : 255;
  195. sh->max_lun = MPT_LAST_LUN + 1;
  196. sh->max_channel = 0;
  197. sh->this_id = ioc->pfacts[0].PortSCSIID;
  198. /* Required entry.
  199. */
  200. sh->unique_id = ioc->id;
  201. /* Verify that we won't exceed the maximum
  202. * number of chain buffers
  203. * We can optimize: ZZ = req_sz/sizeof(SGE)
  204. * For 32bit SGE's:
  205. * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
  206. * + (req_sz - 64)/sizeof(SGE)
  207. * A slightly different algorithm is required for
  208. * 64bit SGEs.
  209. */
  210. scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
  211. if (sizeof(dma_addr_t) == sizeof(u64)) {
  212. numSGE = (scale - 1) *
  213. (ioc->facts.MaxChainDepth-1) + scale +
  214. (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
  215. sizeof(u32));
  216. } else {
  217. numSGE = 1 + (scale - 1) *
  218. (ioc->facts.MaxChainDepth-1) + scale +
  219. (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
  220. sizeof(u32));
  221. }
  222. if (numSGE < sh->sg_tablesize) {
  223. /* Reset this value */
  224. dprintk((MYIOC_s_INFO_FMT
  225. "Resetting sg_tablesize to %d from %d\n",
  226. ioc->name, numSGE, sh->sg_tablesize));
  227. sh->sg_tablesize = numSGE;
  228. }
  229. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  230. hd = (MPT_SCSI_HOST *) sh->hostdata;
  231. hd->ioc = ioc;
  232. /* SCSI needs scsi_cmnd lookup table!
  233. * (with size equal to req_depth*PtrSz!)
  234. */
  235. sz = ioc->req_depth * sizeof(void *);
  236. mem = kmalloc(sz, GFP_ATOMIC);
  237. if (mem == NULL) {
  238. error = -ENOMEM;
  239. goto out_mptfc_probe;
  240. }
  241. memset(mem, 0, sz);
  242. hd->ScsiLookup = (struct scsi_cmnd **) mem;
  243. dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p, sz=%d\n",
  244. ioc->name, hd->ScsiLookup, sz));
  245. /* Allocate memory for the device structures.
  246. * A non-Null pointer at an offset
  247. * indicates a device exists.
  248. * max_id = 1 + maximum id (hosts.h)
  249. */
  250. sz = sh->max_id * sizeof(void *);
  251. mem = kmalloc(sz, GFP_ATOMIC);
  252. if (mem == NULL) {
  253. error = -ENOMEM;
  254. goto out_mptfc_probe;
  255. }
  256. memset(mem, 0, sz);
  257. hd->Targets = (VirtDevice **) mem;
  258. dprintk((KERN_INFO
  259. " Targets @ %p, sz=%d\n", hd->Targets, sz));
  260. /* Clear the TM flags
  261. */
  262. hd->tmPending = 0;
  263. hd->tmState = TM_STATE_NONE;
  264. hd->resetPending = 0;
  265. hd->abortSCpnt = NULL;
  266. /* Clear the pointer used to store
  267. * single-threaded commands, i.e., those
  268. * issued during a bus scan, dv and
  269. * configuration pages.
  270. */
  271. hd->cmdPtr = NULL;
  272. /* Initialize this SCSI Hosts' timers
  273. * To use, set the timer expires field
  274. * and add_timer
  275. */
  276. init_timer(&hd->timer);
  277. hd->timer.data = (unsigned long) hd;
  278. hd->timer.function = mptscsih_timer_expired;
  279. hd->mpt_pq_filter = mpt_pq_filter;
  280. ddvprintk((MYIOC_s_INFO_FMT
  281. "mpt_pq_filter %x\n",
  282. ioc->name,
  283. mpt_pq_filter));
  284. init_waitqueue_head(&hd->scandv_waitq);
  285. hd->scandv_wait_done = 0;
  286. hd->last_queue_full = 0;
  287. error = scsi_add_host (sh, &ioc->pcidev->dev);
  288. if(error) {
  289. dprintk((KERN_ERR MYNAM
  290. "scsi_add_host failed\n"));
  291. goto out_mptfc_probe;
  292. }
  293. scsi_scan_host(sh);
  294. return 0;
  295. out_mptfc_probe:
  296. mptscsih_remove(pdev);
  297. return error;
  298. }
  299. static struct pci_driver mptfc_driver = {
  300. .name = "mptfc",
  301. .id_table = mptfc_pci_table,
  302. .probe = mptfc_probe,
  303. .remove = __devexit_p(mptscsih_remove),
  304. .shutdown = mptscsih_shutdown,
  305. #ifdef CONFIG_PM
  306. .suspend = mptscsih_suspend,
  307. .resume = mptscsih_resume,
  308. #endif
  309. };
  310. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  311. /**
  312. * mptfc_init - Register MPT adapter(s) as SCSI host(s) with
  313. * linux scsi mid-layer.
  314. *
  315. * Returns 0 for success, non-zero for failure.
  316. */
  317. static int __init
  318. mptfc_init(void)
  319. {
  320. show_mptmod_ver(my_NAME, my_VERSION);
  321. mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER);
  322. mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER);
  323. mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER);
  324. if (mpt_event_register(mptfcDoneCtx, mptscsih_event_process) == 0) {
  325. devtprintk((KERN_INFO MYNAM
  326. ": Registered for IOC event notifications\n"));
  327. }
  328. if (mpt_reset_register(mptfcDoneCtx, mptscsih_ioc_reset) == 0) {
  329. dprintk((KERN_INFO MYNAM
  330. ": Registered for IOC reset notifications\n"));
  331. }
  332. return pci_register_driver(&mptfc_driver);
  333. }
  334. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  335. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  336. /**
  337. * mptfc_exit - Unregisters MPT adapter(s)
  338. *
  339. */
  340. static void __exit
  341. mptfc_exit(void)
  342. {
  343. pci_unregister_driver(&mptfc_driver);
  344. mpt_reset_deregister(mptfcDoneCtx);
  345. dprintk((KERN_INFO MYNAM
  346. ": Deregistered for IOC reset notifications\n"));
  347. mpt_event_deregister(mptfcDoneCtx);
  348. dprintk((KERN_INFO MYNAM
  349. ": Deregistered for IOC event notifications\n"));
  350. mpt_deregister(mptfcInternalCtx);
  351. mpt_deregister(mptfcTaskCtx);
  352. mpt_deregister(mptfcDoneCtx);
  353. }
  354. module_init(mptfc_init);
  355. module_exit(mptfc_exit);