bnx2i_init.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /* bnx2i.c: Broadcom NetXtreme II iSCSI driver.
  2. *
  3. * Copyright (c) 2006 - 2010 Broadcom Corporation
  4. * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
  5. * Copyright (c) 2007, 2008 Mike Christie
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation.
  10. *
  11. * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
  12. * Maintained by: Eddie Wai (eddie.wai@broadcom.com)
  13. */
  14. #include "bnx2i.h"
  15. static struct list_head adapter_list = LIST_HEAD_INIT(adapter_list);
  16. static u32 adapter_count;
  17. #define DRV_MODULE_NAME "bnx2i"
  18. #define DRV_MODULE_VERSION "2.6.2.3"
  19. #define DRV_MODULE_RELDATE "Dec 31, 2010"
  20. static char version[] __devinitdata =
  21. "Broadcom NetXtreme II iSCSI Driver " DRV_MODULE_NAME \
  22. " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  23. MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com> and "
  24. "Eddie Wai <eddie.wai@broadcom.com>");
  25. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708/5709/57710/57711/57712"
  26. "/57800/57810/57840 iSCSI Driver");
  27. MODULE_LICENSE("GPL");
  28. MODULE_VERSION(DRV_MODULE_VERSION);
  29. static DEFINE_MUTEX(bnx2i_dev_lock);
  30. unsigned int event_coal_min = 24;
  31. module_param(event_coal_min, int, 0664);
  32. MODULE_PARM_DESC(event_coal_min, "Event Coalescing Minimum Commands");
  33. unsigned int event_coal_div = 1;
  34. module_param(event_coal_div, int, 0664);
  35. MODULE_PARM_DESC(event_coal_div, "Event Coalescing Divide Factor");
  36. unsigned int en_tcp_dack = 1;
  37. module_param(en_tcp_dack, int, 0664);
  38. MODULE_PARM_DESC(en_tcp_dack, "Enable TCP Delayed ACK");
  39. unsigned int error_mask1 = 0x00;
  40. module_param(error_mask1, int, 0664);
  41. MODULE_PARM_DESC(error_mask1, "Config FW iSCSI Error Mask #1");
  42. unsigned int error_mask2 = 0x00;
  43. module_param(error_mask2, int, 0664);
  44. MODULE_PARM_DESC(error_mask2, "Config FW iSCSI Error Mask #2");
  45. unsigned int sq_size;
  46. module_param(sq_size, int, 0664);
  47. MODULE_PARM_DESC(sq_size, "Configure SQ size");
  48. unsigned int rq_size = BNX2I_RQ_WQES_DEFAULT;
  49. module_param(rq_size, int, 0664);
  50. MODULE_PARM_DESC(rq_size, "Configure RQ size");
  51. u64 iscsi_error_mask = 0x00;
  52. /**
  53. * bnx2i_identify_device - identifies NetXtreme II device type
  54. * @hba: Adapter structure pointer
  55. *
  56. * This function identifies the NX2 device type and sets appropriate
  57. * queue mailbox register access method, 5709 requires driver to
  58. * access MBOX regs using *bin* mode
  59. */
  60. void bnx2i_identify_device(struct bnx2i_hba *hba)
  61. {
  62. hba->cnic_dev_type = 0;
  63. if ((hba->pci_did == PCI_DEVICE_ID_NX2_5706) ||
  64. (hba->pci_did == PCI_DEVICE_ID_NX2_5706S))
  65. set_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type);
  66. else if ((hba->pci_did == PCI_DEVICE_ID_NX2_5708) ||
  67. (hba->pci_did == PCI_DEVICE_ID_NX2_5708S))
  68. set_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type);
  69. else if ((hba->pci_did == PCI_DEVICE_ID_NX2_5709) ||
  70. (hba->pci_did == PCI_DEVICE_ID_NX2_5709S)) {
  71. set_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type);
  72. hba->mail_queue_access = BNX2I_MQ_BIN_MODE;
  73. } else if (hba->pci_did == PCI_DEVICE_ID_NX2_57710 ||
  74. hba->pci_did == PCI_DEVICE_ID_NX2_57711 ||
  75. hba->pci_did == PCI_DEVICE_ID_NX2_57711E ||
  76. hba->pci_did == PCI_DEVICE_ID_NX2_57712 ||
  77. hba->pci_did == PCI_DEVICE_ID_NX2_57712E ||
  78. hba->pci_did == PCI_DEVICE_ID_NX2_57800 ||
  79. hba->pci_did == PCI_DEVICE_ID_NX2_57800_MF ||
  80. hba->pci_did == PCI_DEVICE_ID_NX2_57800_VF ||
  81. hba->pci_did == PCI_DEVICE_ID_NX2_57810 ||
  82. hba->pci_did == PCI_DEVICE_ID_NX2_57810_MF ||
  83. hba->pci_did == PCI_DEVICE_ID_NX2_57810_VF ||
  84. hba->pci_did == PCI_DEVICE_ID_NX2_57840 ||
  85. hba->pci_did == PCI_DEVICE_ID_NX2_57840_MF ||
  86. hba->pci_did == PCI_DEVICE_ID_NX2_57840_VF)
  87. set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type);
  88. else
  89. printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n",
  90. hba->pci_did);
  91. }
  92. /**
  93. * get_adapter_list_head - returns head of adapter list
  94. */
  95. struct bnx2i_hba *get_adapter_list_head(void)
  96. {
  97. struct bnx2i_hba *hba = NULL;
  98. struct bnx2i_hba *tmp_hba;
  99. if (!adapter_count)
  100. goto hba_not_found;
  101. mutex_lock(&bnx2i_dev_lock);
  102. list_for_each_entry(tmp_hba, &adapter_list, link) {
  103. if (tmp_hba->cnic && tmp_hba->cnic->cm_select_dev) {
  104. hba = tmp_hba;
  105. break;
  106. }
  107. }
  108. mutex_unlock(&bnx2i_dev_lock);
  109. hba_not_found:
  110. return hba;
  111. }
  112. /**
  113. * bnx2i_find_hba_for_cnic - maps cnic device instance to bnx2i adapter instance
  114. * @cnic: pointer to cnic device instance
  115. *
  116. */
  117. struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic)
  118. {
  119. struct bnx2i_hba *hba, *temp;
  120. mutex_lock(&bnx2i_dev_lock);
  121. list_for_each_entry_safe(hba, temp, &adapter_list, link) {
  122. if (hba->cnic == cnic) {
  123. mutex_unlock(&bnx2i_dev_lock);
  124. return hba;
  125. }
  126. }
  127. mutex_unlock(&bnx2i_dev_lock);
  128. return NULL;
  129. }
  130. /**
  131. * bnx2i_start - cnic callback to initialize & start adapter instance
  132. * @handle: transparent handle pointing to adapter structure
  133. *
  134. * This function maps adapter structure to pcidev structure and initiates
  135. * firmware handshake to enable/initialize on chip iscsi components
  136. * This bnx2i - cnic interface api callback is issued after following
  137. * 2 conditions are met -
  138. * a) underlying network interface is up (marked by event 'NETDEV_UP'
  139. * from netdev
  140. * b) bnx2i adapter instance is registered
  141. */
  142. void bnx2i_start(void *handle)
  143. {
  144. #define BNX2I_INIT_POLL_TIME (1000 / HZ)
  145. struct bnx2i_hba *hba = handle;
  146. int i = HZ;
  147. if (!hba->cnic->max_iscsi_conn) {
  148. printk(KERN_ALERT "bnx2i: dev %s does not support "
  149. "iSCSI\n", hba->netdev->name);
  150. if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
  151. mutex_lock(&bnx2i_dev_lock);
  152. list_del_init(&hba->link);
  153. adapter_count--;
  154. hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
  155. clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
  156. mutex_unlock(&bnx2i_dev_lock);
  157. bnx2i_free_hba(hba);
  158. }
  159. return;
  160. }
  161. bnx2i_send_fw_iscsi_init_msg(hba);
  162. while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
  163. msleep(BNX2I_INIT_POLL_TIME);
  164. }
  165. /**
  166. * bnx2i_chip_cleanup - local routine to handle chip cleanup
  167. * @hba: Adapter instance to register
  168. *
  169. * Driver checks if adapter still has any active connections before
  170. * executing the cleanup process
  171. */
  172. static void bnx2i_chip_cleanup(struct bnx2i_hba *hba)
  173. {
  174. struct bnx2i_endpoint *bnx2i_ep;
  175. struct list_head *pos, *tmp;
  176. if (hba->ofld_conns_active) {
  177. /* Stage to force the disconnection
  178. * This is the case where the daemon is either slow or
  179. * not present
  180. */
  181. printk(KERN_ALERT "bnx2i: (%s) chip cleanup for %d active "
  182. "connections\n", hba->netdev->name,
  183. hba->ofld_conns_active);
  184. mutex_lock(&hba->net_dev_lock);
  185. list_for_each_safe(pos, tmp, &hba->ep_active_list) {
  186. bnx2i_ep = list_entry(pos, struct bnx2i_endpoint, link);
  187. /* Clean up the chip only */
  188. bnx2i_hw_ep_disconnect(bnx2i_ep);
  189. bnx2i_ep->cm_sk = NULL;
  190. }
  191. mutex_unlock(&hba->net_dev_lock);
  192. }
  193. }
  194. /**
  195. * bnx2i_stop - cnic callback to shutdown adapter instance
  196. * @handle: transparent handle pointing to adapter structure
  197. *
  198. * driver checks if adapter is already in shutdown mode, if not start
  199. * the shutdown process
  200. */
  201. void bnx2i_stop(void *handle)
  202. {
  203. struct bnx2i_hba *hba = handle;
  204. int conns_active;
  205. int wait_delay = 1 * HZ;
  206. /* check if cleanup happened in GOING_DOWN context */
  207. if (!test_and_set_bit(ADAPTER_STATE_GOING_DOWN,
  208. &hba->adapter_state)) {
  209. iscsi_host_for_each_session(hba->shost,
  210. bnx2i_drop_session);
  211. wait_delay = hba->hba_shutdown_tmo;
  212. }
  213. /* Wait for inflight offload connection tasks to complete before
  214. * proceeding. Forcefully terminate all connection recovery in
  215. * progress at the earliest, either in bind(), send_pdu(LOGIN),
  216. * or conn_start()
  217. */
  218. wait_event_interruptible_timeout(hba->eh_wait,
  219. (list_empty(&hba->ep_ofld_list) &&
  220. list_empty(&hba->ep_destroy_list)),
  221. 2 * HZ);
  222. /* Wait for all endpoints to be torn down, Chip will be reset once
  223. * control returns to network driver. So it is required to cleanup and
  224. * release all connection resources before returning from this routine.
  225. */
  226. while (hba->ofld_conns_active) {
  227. conns_active = hba->ofld_conns_active;
  228. wait_event_interruptible_timeout(hba->eh_wait,
  229. (hba->ofld_conns_active != conns_active),
  230. wait_delay);
  231. if (hba->ofld_conns_active == conns_active)
  232. break;
  233. }
  234. bnx2i_chip_cleanup(hba);
  235. /* This flag should be cleared last so that ep_disconnect() gracefully
  236. * cleans up connection context
  237. */
  238. clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  239. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  240. }
  241. /**
  242. * bnx2i_init_one - initialize an adapter instance and allocate memory resources
  243. * @hba: bnx2i adapter instance
  244. * @cnic: cnic device handle
  245. *
  246. * Global resource lock is held during critical sections below. This routine is
  247. * called from either cnic_register_driver() or device hot plug context and
  248. * and does majority of device specific initialization
  249. */
  250. static int bnx2i_init_one(struct bnx2i_hba *hba, struct cnic_dev *cnic)
  251. {
  252. int rc;
  253. mutex_lock(&bnx2i_dev_lock);
  254. hba->cnic = cnic;
  255. rc = cnic->register_device(cnic, CNIC_ULP_ISCSI, hba);
  256. if (!rc) {
  257. hba->age++;
  258. set_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
  259. list_add_tail(&hba->link, &adapter_list);
  260. adapter_count++;
  261. } else if (rc == -EBUSY) /* duplicate registration */
  262. printk(KERN_ALERT "bnx2i, duplicate registration"
  263. "hba=%p, cnic=%p\n", hba, cnic);
  264. else if (rc == -EAGAIN)
  265. printk(KERN_ERR "bnx2i, driver not registered\n");
  266. else if (rc == -EINVAL)
  267. printk(KERN_ERR "bnx2i, invalid type %d\n", CNIC_ULP_ISCSI);
  268. else
  269. printk(KERN_ERR "bnx2i dev reg, unknown error, %d\n", rc);
  270. mutex_unlock(&bnx2i_dev_lock);
  271. return rc;
  272. }
  273. /**
  274. * bnx2i_ulp_init - initialize an adapter instance
  275. * @dev: cnic device handle
  276. *
  277. * Called from cnic_register_driver() context to initialize all enumerated
  278. * cnic devices. This routine allocate adapter structure and other
  279. * device specific resources.
  280. */
  281. void bnx2i_ulp_init(struct cnic_dev *dev)
  282. {
  283. struct bnx2i_hba *hba;
  284. /* Allocate a HBA structure for this device */
  285. hba = bnx2i_alloc_hba(dev);
  286. if (!hba) {
  287. printk(KERN_ERR "bnx2i init: hba initialization failed\n");
  288. return;
  289. }
  290. /* Get PCI related information and update hba struct members */
  291. clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
  292. if (bnx2i_init_one(hba, dev)) {
  293. printk(KERN_ERR "bnx2i - hba %p init failed\n", hba);
  294. bnx2i_free_hba(hba);
  295. }
  296. }
  297. /**
  298. * bnx2i_ulp_exit - shuts down adapter instance and frees all resources
  299. * @dev: cnic device handle
  300. *
  301. */
  302. void bnx2i_ulp_exit(struct cnic_dev *dev)
  303. {
  304. struct bnx2i_hba *hba;
  305. hba = bnx2i_find_hba_for_cnic(dev);
  306. if (!hba) {
  307. printk(KERN_INFO "bnx2i_ulp_exit: hba not "
  308. "found, dev 0x%p\n", dev);
  309. return;
  310. }
  311. mutex_lock(&bnx2i_dev_lock);
  312. list_del_init(&hba->link);
  313. adapter_count--;
  314. if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
  315. hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
  316. clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
  317. }
  318. mutex_unlock(&bnx2i_dev_lock);
  319. bnx2i_free_hba(hba);
  320. }
  321. /**
  322. * bnx2i_mod_init - module init entry point
  323. *
  324. * initialize any driver wide global data structures such as endpoint pool,
  325. * tcp port manager/queue, sysfs. finally driver will register itself
  326. * with the cnic module
  327. */
  328. static int __init bnx2i_mod_init(void)
  329. {
  330. int err;
  331. printk(KERN_INFO "%s", version);
  332. if (sq_size && !is_power_of_2(sq_size))
  333. sq_size = roundup_pow_of_two(sq_size);
  334. mutex_init(&bnx2i_dev_lock);
  335. bnx2i_scsi_xport_template =
  336. iscsi_register_transport(&bnx2i_iscsi_transport);
  337. if (!bnx2i_scsi_xport_template) {
  338. printk(KERN_ERR "Could not register bnx2i transport.\n");
  339. err = -ENOMEM;
  340. goto out;
  341. }
  342. err = cnic_register_driver(CNIC_ULP_ISCSI, &bnx2i_cnic_cb);
  343. if (err) {
  344. printk(KERN_ERR "Could not register bnx2i cnic driver.\n");
  345. goto unreg_xport;
  346. }
  347. return 0;
  348. unreg_xport:
  349. iscsi_unregister_transport(&bnx2i_iscsi_transport);
  350. out:
  351. return err;
  352. }
  353. /**
  354. * bnx2i_mod_exit - module cleanup/exit entry point
  355. *
  356. * Global resource lock and host adapter lock is held during critical sections
  357. * in this function. Driver will browse through the adapter list, cleans-up
  358. * each instance, unregisters iscsi transport name and finally driver will
  359. * unregister itself with the cnic module
  360. */
  361. static void __exit bnx2i_mod_exit(void)
  362. {
  363. struct bnx2i_hba *hba;
  364. mutex_lock(&bnx2i_dev_lock);
  365. while (!list_empty(&adapter_list)) {
  366. hba = list_entry(adapter_list.next, struct bnx2i_hba, link);
  367. list_del(&hba->link);
  368. adapter_count--;
  369. if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
  370. bnx2i_chip_cleanup(hba);
  371. hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
  372. clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
  373. }
  374. bnx2i_free_hba(hba);
  375. }
  376. mutex_unlock(&bnx2i_dev_lock);
  377. iscsi_unregister_transport(&bnx2i_iscsi_transport);
  378. cnic_unregister_driver(CNIC_ULP_ISCSI);
  379. }
  380. module_init(bnx2i_mod_init);
  381. module_exit(bnx2i_mod_exit);