bnx2i_init.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. " 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. set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type);
  79. else
  80. printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n",
  81. hba->pci_did);
  82. }
  83. /**
  84. * get_adapter_list_head - returns head of adapter list
  85. */
  86. struct bnx2i_hba *get_adapter_list_head(void)
  87. {
  88. struct bnx2i_hba *hba = NULL;
  89. struct bnx2i_hba *tmp_hba;
  90. if (!adapter_count)
  91. goto hba_not_found;
  92. mutex_lock(&bnx2i_dev_lock);
  93. list_for_each_entry(tmp_hba, &adapter_list, link) {
  94. if (tmp_hba->cnic && tmp_hba->cnic->cm_select_dev) {
  95. hba = tmp_hba;
  96. break;
  97. }
  98. }
  99. mutex_unlock(&bnx2i_dev_lock);
  100. hba_not_found:
  101. return hba;
  102. }
  103. /**
  104. * bnx2i_find_hba_for_cnic - maps cnic device instance to bnx2i adapter instance
  105. * @cnic: pointer to cnic device instance
  106. *
  107. */
  108. struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic)
  109. {
  110. struct bnx2i_hba *hba, *temp;
  111. mutex_lock(&bnx2i_dev_lock);
  112. list_for_each_entry_safe(hba, temp, &adapter_list, link) {
  113. if (hba->cnic == cnic) {
  114. mutex_unlock(&bnx2i_dev_lock);
  115. return hba;
  116. }
  117. }
  118. mutex_unlock(&bnx2i_dev_lock);
  119. return NULL;
  120. }
  121. /**
  122. * bnx2i_start - cnic callback to initialize & start adapter instance
  123. * @handle: transparent handle pointing to adapter structure
  124. *
  125. * This function maps adapter structure to pcidev structure and initiates
  126. * firmware handshake to enable/initialize on chip iscsi components
  127. * This bnx2i - cnic interface api callback is issued after following
  128. * 2 conditions are met -
  129. * a) underlying network interface is up (marked by event 'NETDEV_UP'
  130. * from netdev
  131. * b) bnx2i adapter instance is registered
  132. */
  133. void bnx2i_start(void *handle)
  134. {
  135. #define BNX2I_INIT_POLL_TIME (1000 / HZ)
  136. struct bnx2i_hba *hba = handle;
  137. int i = HZ;
  138. if (!hba->cnic->max_iscsi_conn) {
  139. printk(KERN_ALERT "bnx2i: dev %s does not support "
  140. "iSCSI\n", hba->netdev->name);
  141. if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
  142. mutex_lock(&bnx2i_dev_lock);
  143. list_del_init(&hba->link);
  144. adapter_count--;
  145. hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
  146. clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
  147. mutex_unlock(&bnx2i_dev_lock);
  148. bnx2i_free_hba(hba);
  149. }
  150. return;
  151. }
  152. bnx2i_send_fw_iscsi_init_msg(hba);
  153. while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
  154. msleep(BNX2I_INIT_POLL_TIME);
  155. }
  156. /**
  157. * bnx2i_chip_cleanup - local routine to handle chip cleanup
  158. * @hba: Adapter instance to register
  159. *
  160. * Driver checks if adapter still has any active connections before
  161. * executing the cleanup process
  162. */
  163. static void bnx2i_chip_cleanup(struct bnx2i_hba *hba)
  164. {
  165. struct bnx2i_endpoint *bnx2i_ep;
  166. struct list_head *pos, *tmp;
  167. if (hba->ofld_conns_active) {
  168. /* Stage to force the disconnection
  169. * This is the case where the daemon is either slow or
  170. * not present
  171. */
  172. printk(KERN_ALERT "bnx2i: (%s) chip cleanup for %d active "
  173. "connections\n", hba->netdev->name,
  174. hba->ofld_conns_active);
  175. mutex_lock(&hba->net_dev_lock);
  176. list_for_each_safe(pos, tmp, &hba->ep_active_list) {
  177. bnx2i_ep = list_entry(pos, struct bnx2i_endpoint, link);
  178. /* Clean up the chip only */
  179. bnx2i_hw_ep_disconnect(bnx2i_ep);
  180. bnx2i_ep->cm_sk = NULL;
  181. }
  182. mutex_unlock(&hba->net_dev_lock);
  183. }
  184. }
  185. /**
  186. * bnx2i_stop - cnic callback to shutdown adapter instance
  187. * @handle: transparent handle pointing to adapter structure
  188. *
  189. * driver checks if adapter is already in shutdown mode, if not start
  190. * the shutdown process
  191. */
  192. void bnx2i_stop(void *handle)
  193. {
  194. struct bnx2i_hba *hba = handle;
  195. int conns_active;
  196. int wait_delay = 1 * HZ;
  197. /* check if cleanup happened in GOING_DOWN context */
  198. if (!test_and_set_bit(ADAPTER_STATE_GOING_DOWN,
  199. &hba->adapter_state)) {
  200. iscsi_host_for_each_session(hba->shost,
  201. bnx2i_drop_session);
  202. wait_delay = hba->hba_shutdown_tmo;
  203. }
  204. /* Wait for inflight offload connection tasks to complete before
  205. * proceeding. Forcefully terminate all connection recovery in
  206. * progress at the earliest, either in bind(), send_pdu(LOGIN),
  207. * or conn_start()
  208. */
  209. wait_event_interruptible_timeout(hba->eh_wait,
  210. (list_empty(&hba->ep_ofld_list) &&
  211. list_empty(&hba->ep_destroy_list)),
  212. 10 * HZ);
  213. /* Wait for all endpoints to be torn down, Chip will be reset once
  214. * control returns to network driver. So it is required to cleanup and
  215. * release all connection resources before returning from this routine.
  216. */
  217. while (hba->ofld_conns_active) {
  218. conns_active = hba->ofld_conns_active;
  219. wait_event_interruptible_timeout(hba->eh_wait,
  220. (hba->ofld_conns_active != conns_active),
  221. wait_delay);
  222. if (hba->ofld_conns_active == conns_active)
  223. break;
  224. }
  225. bnx2i_chip_cleanup(hba);
  226. /* This flag should be cleared last so that ep_disconnect() gracefully
  227. * cleans up connection context
  228. */
  229. clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  230. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  231. }
  232. /**
  233. * bnx2i_init_one - initialize an adapter instance and allocate memory resources
  234. * @hba: bnx2i adapter instance
  235. * @cnic: cnic device handle
  236. *
  237. * Global resource lock is held during critical sections below. This routine is
  238. * called from either cnic_register_driver() or device hot plug context and
  239. * and does majority of device specific initialization
  240. */
  241. static int bnx2i_init_one(struct bnx2i_hba *hba, struct cnic_dev *cnic)
  242. {
  243. int rc;
  244. mutex_lock(&bnx2i_dev_lock);
  245. hba->cnic = cnic;
  246. rc = cnic->register_device(cnic, CNIC_ULP_ISCSI, hba);
  247. if (!rc) {
  248. hba->age++;
  249. set_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
  250. list_add_tail(&hba->link, &adapter_list);
  251. adapter_count++;
  252. } else if (rc == -EBUSY) /* duplicate registration */
  253. printk(KERN_ALERT "bnx2i, duplicate registration"
  254. "hba=%p, cnic=%p\n", hba, cnic);
  255. else if (rc == -EAGAIN)
  256. printk(KERN_ERR "bnx2i, driver not registered\n");
  257. else if (rc == -EINVAL)
  258. printk(KERN_ERR "bnx2i, invalid type %d\n", CNIC_ULP_ISCSI);
  259. else
  260. printk(KERN_ERR "bnx2i dev reg, unknown error, %d\n", rc);
  261. mutex_unlock(&bnx2i_dev_lock);
  262. return rc;
  263. }
  264. /**
  265. * bnx2i_ulp_init - initialize an adapter instance
  266. * @dev: cnic device handle
  267. *
  268. * Called from cnic_register_driver() context to initialize all enumerated
  269. * cnic devices. This routine allocate adapter structure and other
  270. * device specific resources.
  271. */
  272. void bnx2i_ulp_init(struct cnic_dev *dev)
  273. {
  274. struct bnx2i_hba *hba;
  275. /* Allocate a HBA structure for this device */
  276. hba = bnx2i_alloc_hba(dev);
  277. if (!hba) {
  278. printk(KERN_ERR "bnx2i init: hba initialization failed\n");
  279. return;
  280. }
  281. /* Get PCI related information and update hba struct members */
  282. clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
  283. if (bnx2i_init_one(hba, dev)) {
  284. printk(KERN_ERR "bnx2i - hba %p init failed\n", hba);
  285. bnx2i_free_hba(hba);
  286. }
  287. }
  288. /**
  289. * bnx2i_ulp_exit - shuts down adapter instance and frees all resources
  290. * @dev: cnic device handle
  291. *
  292. */
  293. void bnx2i_ulp_exit(struct cnic_dev *dev)
  294. {
  295. struct bnx2i_hba *hba;
  296. hba = bnx2i_find_hba_for_cnic(dev);
  297. if (!hba) {
  298. printk(KERN_INFO "bnx2i_ulp_exit: hba not "
  299. "found, dev 0x%p\n", dev);
  300. return;
  301. }
  302. mutex_lock(&bnx2i_dev_lock);
  303. list_del_init(&hba->link);
  304. adapter_count--;
  305. if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
  306. hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
  307. clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
  308. }
  309. mutex_unlock(&bnx2i_dev_lock);
  310. bnx2i_free_hba(hba);
  311. }
  312. /**
  313. * bnx2i_mod_init - module init entry point
  314. *
  315. * initialize any driver wide global data structures such as endpoint pool,
  316. * tcp port manager/queue, sysfs. finally driver will register itself
  317. * with the cnic module
  318. */
  319. static int __init bnx2i_mod_init(void)
  320. {
  321. int err;
  322. printk(KERN_INFO "%s", version);
  323. if (sq_size && !is_power_of_2(sq_size))
  324. sq_size = roundup_pow_of_two(sq_size);
  325. mutex_init(&bnx2i_dev_lock);
  326. bnx2i_scsi_xport_template =
  327. iscsi_register_transport(&bnx2i_iscsi_transport);
  328. if (!bnx2i_scsi_xport_template) {
  329. printk(KERN_ERR "Could not register bnx2i transport.\n");
  330. err = -ENOMEM;
  331. goto out;
  332. }
  333. err = cnic_register_driver(CNIC_ULP_ISCSI, &bnx2i_cnic_cb);
  334. if (err) {
  335. printk(KERN_ERR "Could not register bnx2i cnic driver.\n");
  336. goto unreg_xport;
  337. }
  338. return 0;
  339. unreg_xport:
  340. iscsi_unregister_transport(&bnx2i_iscsi_transport);
  341. out:
  342. return err;
  343. }
  344. /**
  345. * bnx2i_mod_exit - module cleanup/exit entry point
  346. *
  347. * Global resource lock and host adapter lock is held during critical sections
  348. * in this function. Driver will browse through the adapter list, cleans-up
  349. * each instance, unregisters iscsi transport name and finally driver will
  350. * unregister itself with the cnic module
  351. */
  352. static void __exit bnx2i_mod_exit(void)
  353. {
  354. struct bnx2i_hba *hba;
  355. mutex_lock(&bnx2i_dev_lock);
  356. while (!list_empty(&adapter_list)) {
  357. hba = list_entry(adapter_list.next, struct bnx2i_hba, link);
  358. list_del(&hba->link);
  359. adapter_count--;
  360. if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
  361. bnx2i_chip_cleanup(hba);
  362. hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
  363. clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
  364. }
  365. bnx2i_free_hba(hba);
  366. }
  367. mutex_unlock(&bnx2i_dev_lock);
  368. iscsi_unregister_transport(&bnx2i_iscsi_transport);
  369. cnic_unregister_driver(CNIC_ULP_ISCSI);
  370. }
  371. module_init(bnx2i_mod_init);
  372. module_exit(bnx2i_mod_exit);