fnic_main.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. /*
  2. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  3. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  4. *
  5. * This program is free software; you may redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  12. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  13. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  14. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. * SOFTWARE.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/mempool.h>
  20. #include <linux/string.h>
  21. #include <linux/slab.h>
  22. #include <linux/errno.h>
  23. #include <linux/init.h>
  24. #include <linux/pci.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/workqueue.h>
  29. #include <linux/if_ether.h>
  30. #include <scsi/fc/fc_fip.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_transport.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include <scsi/scsi_tcq.h>
  35. #include <scsi/libfc.h>
  36. #include <scsi/fc_frame.h>
  37. #include "vnic_dev.h"
  38. #include "vnic_intr.h"
  39. #include "vnic_stats.h"
  40. #include "fnic_io.h"
  41. #include "fnic_fip.h"
  42. #include "fnic.h"
  43. #define PCI_DEVICE_ID_CISCO_FNIC 0x0045
  44. /* Timer to poll notification area for events. Used for MSI interrupts */
  45. #define FNIC_NOTIFY_TIMER_PERIOD (2 * HZ)
  46. static struct kmem_cache *fnic_sgl_cache[FNIC_SGL_NUM_CACHES];
  47. static struct kmem_cache *fnic_io_req_cache;
  48. LIST_HEAD(fnic_list);
  49. DEFINE_SPINLOCK(fnic_list_lock);
  50. /* Supported devices by fnic module */
  51. static struct pci_device_id fnic_id_table[] = {
  52. { PCI_DEVICE(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_FNIC) },
  53. { 0, }
  54. };
  55. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  56. MODULE_AUTHOR("Abhijeet Joglekar <abjoglek@cisco.com>, "
  57. "Joseph R. Eykholt <jeykholt@cisco.com>");
  58. MODULE_LICENSE("GPL v2");
  59. MODULE_VERSION(DRV_VERSION);
  60. MODULE_DEVICE_TABLE(pci, fnic_id_table);
  61. unsigned int fnic_log_level;
  62. module_param(fnic_log_level, int, S_IRUGO|S_IWUSR);
  63. MODULE_PARM_DESC(fnic_log_level, "bit mask of fnic logging levels");
  64. unsigned int fnic_trace_max_pages = 16;
  65. module_param(fnic_trace_max_pages, uint, S_IRUGO|S_IWUSR);
  66. MODULE_PARM_DESC(fnic_trace_max_pages, "Total allocated memory pages "
  67. "for fnic trace buffer");
  68. unsigned int fnic_fc_trace_max_pages = 64;
  69. module_param(fnic_fc_trace_max_pages, uint, S_IRUGO|S_IWUSR);
  70. MODULE_PARM_DESC(fnic_fc_trace_max_pages,
  71. "Total allocated memory pages for fc trace buffer");
  72. static unsigned int fnic_max_qdepth = FNIC_DFLT_QUEUE_DEPTH;
  73. module_param(fnic_max_qdepth, uint, S_IRUGO|S_IWUSR);
  74. MODULE_PARM_DESC(fnic_max_qdepth, "Queue depth to report for each LUN");
  75. static struct libfc_function_template fnic_transport_template = {
  76. .frame_send = fnic_send,
  77. .lport_set_port_id = fnic_set_port_id,
  78. .fcp_abort_io = fnic_empty_scsi_cleanup,
  79. .fcp_cleanup = fnic_empty_scsi_cleanup,
  80. .exch_mgr_reset = fnic_exch_mgr_reset
  81. };
  82. static int fnic_slave_alloc(struct scsi_device *sdev)
  83. {
  84. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  85. if (!rport || fc_remote_port_chkready(rport))
  86. return -ENXIO;
  87. scsi_change_queue_depth(sdev, fnic_max_qdepth);
  88. return 0;
  89. }
  90. static struct scsi_host_template fnic_host_template = {
  91. .module = THIS_MODULE,
  92. .name = DRV_NAME,
  93. .queuecommand = fnic_queuecommand,
  94. .eh_abort_handler = fnic_abort_cmd,
  95. .eh_device_reset_handler = fnic_device_reset,
  96. .eh_host_reset_handler = fnic_host_reset,
  97. .slave_alloc = fnic_slave_alloc,
  98. .change_queue_depth = scsi_change_queue_depth,
  99. .this_id = -1,
  100. .cmd_per_lun = 3,
  101. .can_queue = FNIC_DFLT_IO_REQ,
  102. .use_clustering = ENABLE_CLUSTERING,
  103. .sg_tablesize = FNIC_MAX_SG_DESC_CNT,
  104. .max_sectors = 0xffff,
  105. .shost_attrs = fnic_attrs,
  106. .track_queue_depth = 1,
  107. };
  108. static void
  109. fnic_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
  110. {
  111. if (timeout)
  112. rport->dev_loss_tmo = timeout;
  113. else
  114. rport->dev_loss_tmo = 1;
  115. }
  116. static void fnic_get_host_speed(struct Scsi_Host *shost);
  117. static struct scsi_transport_template *fnic_fc_transport;
  118. static struct fc_host_statistics *fnic_get_stats(struct Scsi_Host *);
  119. static void fnic_reset_host_stats(struct Scsi_Host *);
  120. static struct fc_function_template fnic_fc_functions = {
  121. .show_host_node_name = 1,
  122. .show_host_port_name = 1,
  123. .show_host_supported_classes = 1,
  124. .show_host_supported_fc4s = 1,
  125. .show_host_active_fc4s = 1,
  126. .show_host_maxframe_size = 1,
  127. .show_host_port_id = 1,
  128. .show_host_supported_speeds = 1,
  129. .get_host_speed = fnic_get_host_speed,
  130. .show_host_speed = 1,
  131. .show_host_port_type = 1,
  132. .get_host_port_state = fc_get_host_port_state,
  133. .show_host_port_state = 1,
  134. .show_host_symbolic_name = 1,
  135. .show_rport_maxframe_size = 1,
  136. .show_rport_supported_classes = 1,
  137. .show_host_fabric_name = 1,
  138. .show_starget_node_name = 1,
  139. .show_starget_port_name = 1,
  140. .show_starget_port_id = 1,
  141. .show_rport_dev_loss_tmo = 1,
  142. .set_rport_dev_loss_tmo = fnic_set_rport_dev_loss_tmo,
  143. .issue_fc_host_lip = fnic_reset,
  144. .get_fc_host_stats = fnic_get_stats,
  145. .reset_fc_host_stats = fnic_reset_host_stats,
  146. .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
  147. .terminate_rport_io = fnic_terminate_rport_io,
  148. .bsg_request = fc_lport_bsg_request,
  149. };
  150. static void fnic_get_host_speed(struct Scsi_Host *shost)
  151. {
  152. struct fc_lport *lp = shost_priv(shost);
  153. struct fnic *fnic = lport_priv(lp);
  154. u32 port_speed = vnic_dev_port_speed(fnic->vdev);
  155. /* Add in other values as they get defined in fw */
  156. switch (port_speed) {
  157. case 10000:
  158. fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
  159. break;
  160. default:
  161. fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
  162. break;
  163. }
  164. }
  165. static struct fc_host_statistics *fnic_get_stats(struct Scsi_Host *host)
  166. {
  167. int ret;
  168. struct fc_lport *lp = shost_priv(host);
  169. struct fnic *fnic = lport_priv(lp);
  170. struct fc_host_statistics *stats = &lp->host_stats;
  171. struct vnic_stats *vs;
  172. unsigned long flags;
  173. if (time_before(jiffies, fnic->stats_time + HZ / FNIC_STATS_RATE_LIMIT))
  174. return stats;
  175. fnic->stats_time = jiffies;
  176. spin_lock_irqsave(&fnic->fnic_lock, flags);
  177. ret = vnic_dev_stats_dump(fnic->vdev, &fnic->stats);
  178. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  179. if (ret) {
  180. FNIC_MAIN_DBG(KERN_DEBUG, fnic->lport->host,
  181. "fnic: Get vnic stats failed"
  182. " 0x%x", ret);
  183. return stats;
  184. }
  185. vs = fnic->stats;
  186. stats->tx_frames = vs->tx.tx_unicast_frames_ok;
  187. stats->tx_words = vs->tx.tx_unicast_bytes_ok / 4;
  188. stats->rx_frames = vs->rx.rx_unicast_frames_ok;
  189. stats->rx_words = vs->rx.rx_unicast_bytes_ok / 4;
  190. stats->error_frames = vs->tx.tx_errors + vs->rx.rx_errors;
  191. stats->dumped_frames = vs->tx.tx_drops + vs->rx.rx_drop;
  192. stats->invalid_crc_count = vs->rx.rx_crc_errors;
  193. stats->seconds_since_last_reset =
  194. (jiffies - fnic->stats_reset_time) / HZ;
  195. stats->fcp_input_megabytes = div_u64(fnic->fcp_input_bytes, 1000000);
  196. stats->fcp_output_megabytes = div_u64(fnic->fcp_output_bytes, 1000000);
  197. return stats;
  198. }
  199. /*
  200. * fnic_dump_fchost_stats
  201. * note : dumps fc_statistics into system logs
  202. */
  203. void fnic_dump_fchost_stats(struct Scsi_Host *host,
  204. struct fc_host_statistics *stats)
  205. {
  206. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  207. "fnic: seconds since last reset = %llu\n",
  208. stats->seconds_since_last_reset);
  209. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  210. "fnic: tx frames = %llu\n",
  211. stats->tx_frames);
  212. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  213. "fnic: tx words = %llu\n",
  214. stats->tx_words);
  215. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  216. "fnic: rx frames = %llu\n",
  217. stats->rx_frames);
  218. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  219. "fnic: rx words = %llu\n",
  220. stats->rx_words);
  221. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  222. "fnic: lip count = %llu\n",
  223. stats->lip_count);
  224. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  225. "fnic: nos count = %llu\n",
  226. stats->nos_count);
  227. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  228. "fnic: error frames = %llu\n",
  229. stats->error_frames);
  230. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  231. "fnic: dumped frames = %llu\n",
  232. stats->dumped_frames);
  233. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  234. "fnic: link failure count = %llu\n",
  235. stats->link_failure_count);
  236. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  237. "fnic: loss of sync count = %llu\n",
  238. stats->loss_of_sync_count);
  239. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  240. "fnic: loss of signal count = %llu\n",
  241. stats->loss_of_signal_count);
  242. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  243. "fnic: prim seq protocol err count = %llu\n",
  244. stats->prim_seq_protocol_err_count);
  245. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  246. "fnic: invalid tx word count= %llu\n",
  247. stats->invalid_tx_word_count);
  248. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  249. "fnic: invalid crc count = %llu\n",
  250. stats->invalid_crc_count);
  251. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  252. "fnic: fcp input requests = %llu\n",
  253. stats->fcp_input_requests);
  254. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  255. "fnic: fcp output requests = %llu\n",
  256. stats->fcp_output_requests);
  257. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  258. "fnic: fcp control requests = %llu\n",
  259. stats->fcp_control_requests);
  260. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  261. "fnic: fcp input megabytes = %llu\n",
  262. stats->fcp_input_megabytes);
  263. FNIC_MAIN_NOTE(KERN_NOTICE, host,
  264. "fnic: fcp output megabytes = %llu\n",
  265. stats->fcp_output_megabytes);
  266. return;
  267. }
  268. /*
  269. * fnic_reset_host_stats : clears host stats
  270. * note : called when reset_statistics set under sysfs dir
  271. */
  272. static void fnic_reset_host_stats(struct Scsi_Host *host)
  273. {
  274. int ret;
  275. struct fc_lport *lp = shost_priv(host);
  276. struct fnic *fnic = lport_priv(lp);
  277. struct fc_host_statistics *stats;
  278. unsigned long flags;
  279. /* dump current stats, before clearing them */
  280. stats = fnic_get_stats(host);
  281. fnic_dump_fchost_stats(host, stats);
  282. spin_lock_irqsave(&fnic->fnic_lock, flags);
  283. ret = vnic_dev_stats_clear(fnic->vdev);
  284. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  285. if (ret) {
  286. FNIC_MAIN_DBG(KERN_DEBUG, fnic->lport->host,
  287. "fnic: Reset vnic stats failed"
  288. " 0x%x", ret);
  289. return;
  290. }
  291. fnic->stats_reset_time = jiffies;
  292. memset(stats, 0, sizeof(*stats));
  293. return;
  294. }
  295. void fnic_log_q_error(struct fnic *fnic)
  296. {
  297. unsigned int i;
  298. u32 error_status;
  299. for (i = 0; i < fnic->raw_wq_count; i++) {
  300. error_status = ioread32(&fnic->wq[i].ctrl->error_status);
  301. if (error_status)
  302. shost_printk(KERN_ERR, fnic->lport->host,
  303. "WQ[%d] error_status"
  304. " %d\n", i, error_status);
  305. }
  306. for (i = 0; i < fnic->rq_count; i++) {
  307. error_status = ioread32(&fnic->rq[i].ctrl->error_status);
  308. if (error_status)
  309. shost_printk(KERN_ERR, fnic->lport->host,
  310. "RQ[%d] error_status"
  311. " %d\n", i, error_status);
  312. }
  313. for (i = 0; i < fnic->wq_copy_count; i++) {
  314. error_status = ioread32(&fnic->wq_copy[i].ctrl->error_status);
  315. if (error_status)
  316. shost_printk(KERN_ERR, fnic->lport->host,
  317. "CWQ[%d] error_status"
  318. " %d\n", i, error_status);
  319. }
  320. }
  321. void fnic_handle_link_event(struct fnic *fnic)
  322. {
  323. unsigned long flags;
  324. spin_lock_irqsave(&fnic->fnic_lock, flags);
  325. if (fnic->stop_rx_link_events) {
  326. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  327. return;
  328. }
  329. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  330. queue_work(fnic_event_queue, &fnic->link_work);
  331. }
  332. static int fnic_notify_set(struct fnic *fnic)
  333. {
  334. int err;
  335. switch (vnic_dev_get_intr_mode(fnic->vdev)) {
  336. case VNIC_DEV_INTR_MODE_INTX:
  337. err = vnic_dev_notify_set(fnic->vdev, FNIC_INTX_NOTIFY);
  338. break;
  339. case VNIC_DEV_INTR_MODE_MSI:
  340. err = vnic_dev_notify_set(fnic->vdev, -1);
  341. break;
  342. case VNIC_DEV_INTR_MODE_MSIX:
  343. err = vnic_dev_notify_set(fnic->vdev, FNIC_MSIX_ERR_NOTIFY);
  344. break;
  345. default:
  346. shost_printk(KERN_ERR, fnic->lport->host,
  347. "Interrupt mode should be set up"
  348. " before devcmd notify set %d\n",
  349. vnic_dev_get_intr_mode(fnic->vdev));
  350. err = -1;
  351. break;
  352. }
  353. return err;
  354. }
  355. static void fnic_notify_timer(unsigned long data)
  356. {
  357. struct fnic *fnic = (struct fnic *)data;
  358. fnic_handle_link_event(fnic);
  359. mod_timer(&fnic->notify_timer,
  360. round_jiffies(jiffies + FNIC_NOTIFY_TIMER_PERIOD));
  361. }
  362. static void fnic_fip_notify_timer(unsigned long data)
  363. {
  364. struct fnic *fnic = (struct fnic *)data;
  365. fnic_handle_fip_timer(fnic);
  366. }
  367. static void fnic_notify_timer_start(struct fnic *fnic)
  368. {
  369. switch (vnic_dev_get_intr_mode(fnic->vdev)) {
  370. case VNIC_DEV_INTR_MODE_MSI:
  371. /*
  372. * Schedule first timeout immediately. The driver is
  373. * initiatialized and ready to look for link up notification
  374. */
  375. mod_timer(&fnic->notify_timer, jiffies);
  376. break;
  377. default:
  378. /* Using intr for notification for INTx/MSI-X */
  379. break;
  380. };
  381. }
  382. static int fnic_dev_wait(struct vnic_dev *vdev,
  383. int (*start)(struct vnic_dev *, int),
  384. int (*finished)(struct vnic_dev *, int *),
  385. int arg)
  386. {
  387. unsigned long time;
  388. int done;
  389. int err;
  390. int count;
  391. count = 0;
  392. err = start(vdev, arg);
  393. if (err)
  394. return err;
  395. /* Wait for func to complete.
  396. * Sometime schedule_timeout_uninterruptible take long time
  397. * to wake up so we do not retry as we are only waiting for
  398. * 2 seconds in while loop. By adding count, we make sure
  399. * we try atleast three times before returning -ETIMEDOUT
  400. */
  401. time = jiffies + (HZ * 2);
  402. do {
  403. err = finished(vdev, &done);
  404. count++;
  405. if (err)
  406. return err;
  407. if (done)
  408. return 0;
  409. schedule_timeout_uninterruptible(HZ / 10);
  410. } while (time_after(time, jiffies) || (count < 3));
  411. return -ETIMEDOUT;
  412. }
  413. static int fnic_cleanup(struct fnic *fnic)
  414. {
  415. unsigned int i;
  416. int err;
  417. vnic_dev_disable(fnic->vdev);
  418. for (i = 0; i < fnic->intr_count; i++)
  419. vnic_intr_mask(&fnic->intr[i]);
  420. for (i = 0; i < fnic->rq_count; i++) {
  421. err = vnic_rq_disable(&fnic->rq[i]);
  422. if (err)
  423. return err;
  424. }
  425. for (i = 0; i < fnic->raw_wq_count; i++) {
  426. err = vnic_wq_disable(&fnic->wq[i]);
  427. if (err)
  428. return err;
  429. }
  430. for (i = 0; i < fnic->wq_copy_count; i++) {
  431. err = vnic_wq_copy_disable(&fnic->wq_copy[i]);
  432. if (err)
  433. return err;
  434. }
  435. /* Clean up completed IOs and FCS frames */
  436. fnic_wq_copy_cmpl_handler(fnic, -1);
  437. fnic_wq_cmpl_handler(fnic, -1);
  438. fnic_rq_cmpl_handler(fnic, -1);
  439. /* Clean up the IOs and FCS frames that have not completed */
  440. for (i = 0; i < fnic->raw_wq_count; i++)
  441. vnic_wq_clean(&fnic->wq[i], fnic_free_wq_buf);
  442. for (i = 0; i < fnic->rq_count; i++)
  443. vnic_rq_clean(&fnic->rq[i], fnic_free_rq_buf);
  444. for (i = 0; i < fnic->wq_copy_count; i++)
  445. vnic_wq_copy_clean(&fnic->wq_copy[i],
  446. fnic_wq_copy_cleanup_handler);
  447. for (i = 0; i < fnic->cq_count; i++)
  448. vnic_cq_clean(&fnic->cq[i]);
  449. for (i = 0; i < fnic->intr_count; i++)
  450. vnic_intr_clean(&fnic->intr[i]);
  451. mempool_destroy(fnic->io_req_pool);
  452. for (i = 0; i < FNIC_SGL_NUM_CACHES; i++)
  453. mempool_destroy(fnic->io_sgl_pool[i]);
  454. return 0;
  455. }
  456. static void fnic_iounmap(struct fnic *fnic)
  457. {
  458. if (fnic->bar0.vaddr)
  459. iounmap(fnic->bar0.vaddr);
  460. }
  461. /**
  462. * fnic_get_mac() - get assigned data MAC address for FIP code.
  463. * @lport: local port.
  464. */
  465. static u8 *fnic_get_mac(struct fc_lport *lport)
  466. {
  467. struct fnic *fnic = lport_priv(lport);
  468. return fnic->data_src_addr;
  469. }
  470. static void fnic_set_vlan(struct fnic *fnic, u16 vlan_id)
  471. {
  472. u16 old_vlan;
  473. old_vlan = vnic_dev_set_default_vlan(fnic->vdev, vlan_id);
  474. }
  475. static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  476. {
  477. struct Scsi_Host *host;
  478. struct fc_lport *lp;
  479. struct fnic *fnic;
  480. mempool_t *pool;
  481. int err;
  482. int i;
  483. unsigned long flags;
  484. /*
  485. * Allocate SCSI Host and set up association between host,
  486. * local port, and fnic
  487. */
  488. lp = libfc_host_alloc(&fnic_host_template, sizeof(struct fnic));
  489. if (!lp) {
  490. printk(KERN_ERR PFX "Unable to alloc libfc local port\n");
  491. err = -ENOMEM;
  492. goto err_out;
  493. }
  494. host = lp->host;
  495. fnic = lport_priv(lp);
  496. fnic->lport = lp;
  497. fnic->ctlr.lp = lp;
  498. snprintf(fnic->name, sizeof(fnic->name) - 1, "%s%d", DRV_NAME,
  499. host->host_no);
  500. host->transportt = fnic_fc_transport;
  501. err = fnic_stats_debugfs_init(fnic);
  502. if (err) {
  503. shost_printk(KERN_ERR, fnic->lport->host,
  504. "Failed to initialize debugfs for stats\n");
  505. fnic_stats_debugfs_remove(fnic);
  506. }
  507. /* Setup PCI resources */
  508. pci_set_drvdata(pdev, fnic);
  509. fnic->pdev = pdev;
  510. err = pci_enable_device(pdev);
  511. if (err) {
  512. shost_printk(KERN_ERR, fnic->lport->host,
  513. "Cannot enable PCI device, aborting.\n");
  514. goto err_out_free_hba;
  515. }
  516. err = pci_request_regions(pdev, DRV_NAME);
  517. if (err) {
  518. shost_printk(KERN_ERR, fnic->lport->host,
  519. "Cannot enable PCI resources, aborting\n");
  520. goto err_out_disable_device;
  521. }
  522. pci_set_master(pdev);
  523. /* Query PCI controller on system for DMA addressing
  524. * limitation for the device. Try 64-bit first, and
  525. * fail to 32-bit.
  526. */
  527. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  528. if (err) {
  529. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  530. if (err) {
  531. shost_printk(KERN_ERR, fnic->lport->host,
  532. "No usable DMA configuration "
  533. "aborting\n");
  534. goto err_out_release_regions;
  535. }
  536. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  537. if (err) {
  538. shost_printk(KERN_ERR, fnic->lport->host,
  539. "Unable to obtain 32-bit DMA "
  540. "for consistent allocations, aborting.\n");
  541. goto err_out_release_regions;
  542. }
  543. } else {
  544. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  545. if (err) {
  546. shost_printk(KERN_ERR, fnic->lport->host,
  547. "Unable to obtain 64-bit DMA "
  548. "for consistent allocations, aborting.\n");
  549. goto err_out_release_regions;
  550. }
  551. }
  552. /* Map vNIC resources from BAR0 */
  553. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  554. shost_printk(KERN_ERR, fnic->lport->host,
  555. "BAR0 not memory-map'able, aborting.\n");
  556. err = -ENODEV;
  557. goto err_out_release_regions;
  558. }
  559. fnic->bar0.vaddr = pci_iomap(pdev, 0, 0);
  560. fnic->bar0.bus_addr = pci_resource_start(pdev, 0);
  561. fnic->bar0.len = pci_resource_len(pdev, 0);
  562. if (!fnic->bar0.vaddr) {
  563. shost_printk(KERN_ERR, fnic->lport->host,
  564. "Cannot memory-map BAR0 res hdr, "
  565. "aborting.\n");
  566. err = -ENODEV;
  567. goto err_out_release_regions;
  568. }
  569. fnic->vdev = vnic_dev_register(NULL, fnic, pdev, &fnic->bar0);
  570. if (!fnic->vdev) {
  571. shost_printk(KERN_ERR, fnic->lport->host,
  572. "vNIC registration failed, "
  573. "aborting.\n");
  574. err = -ENODEV;
  575. goto err_out_iounmap;
  576. }
  577. err = fnic_dev_wait(fnic->vdev, vnic_dev_open,
  578. vnic_dev_open_done, 0);
  579. if (err) {
  580. shost_printk(KERN_ERR, fnic->lport->host,
  581. "vNIC dev open failed, aborting.\n");
  582. goto err_out_vnic_unregister;
  583. }
  584. err = vnic_dev_init(fnic->vdev, 0);
  585. if (err) {
  586. shost_printk(KERN_ERR, fnic->lport->host,
  587. "vNIC dev init failed, aborting.\n");
  588. goto err_out_dev_close;
  589. }
  590. err = vnic_dev_mac_addr(fnic->vdev, fnic->ctlr.ctl_src_addr);
  591. if (err) {
  592. shost_printk(KERN_ERR, fnic->lport->host,
  593. "vNIC get MAC addr failed \n");
  594. goto err_out_dev_close;
  595. }
  596. /* set data_src for point-to-point mode and to keep it non-zero */
  597. memcpy(fnic->data_src_addr, fnic->ctlr.ctl_src_addr, ETH_ALEN);
  598. /* Get vNIC configuration */
  599. err = fnic_get_vnic_config(fnic);
  600. if (err) {
  601. shost_printk(KERN_ERR, fnic->lport->host,
  602. "Get vNIC configuration failed, "
  603. "aborting.\n");
  604. goto err_out_dev_close;
  605. }
  606. /* Configure Maximum Outstanding IO reqs*/
  607. if (fnic->config.io_throttle_count != FNIC_UCSM_DFLT_THROTTLE_CNT_BLD) {
  608. host->can_queue = min_t(u32, FNIC_MAX_IO_REQ,
  609. max_t(u32, FNIC_MIN_IO_REQ,
  610. fnic->config.io_throttle_count));
  611. }
  612. fnic->fnic_max_tag_id = host->can_queue;
  613. host->max_lun = fnic->config.luns_per_tgt;
  614. host->max_id = FNIC_MAX_FCP_TARGET;
  615. host->max_cmd_len = FCOE_MAX_CMD_LEN;
  616. fnic_get_res_counts(fnic);
  617. err = fnic_set_intr_mode(fnic);
  618. if (err) {
  619. shost_printk(KERN_ERR, fnic->lport->host,
  620. "Failed to set intr mode, "
  621. "aborting.\n");
  622. goto err_out_dev_close;
  623. }
  624. err = fnic_alloc_vnic_resources(fnic);
  625. if (err) {
  626. shost_printk(KERN_ERR, fnic->lport->host,
  627. "Failed to alloc vNIC resources, "
  628. "aborting.\n");
  629. goto err_out_clear_intr;
  630. }
  631. /* initialize all fnic locks */
  632. spin_lock_init(&fnic->fnic_lock);
  633. for (i = 0; i < FNIC_WQ_MAX; i++)
  634. spin_lock_init(&fnic->wq_lock[i]);
  635. for (i = 0; i < FNIC_WQ_COPY_MAX; i++) {
  636. spin_lock_init(&fnic->wq_copy_lock[i]);
  637. fnic->wq_copy_desc_low[i] = DESC_CLEAN_LOW_WATERMARK;
  638. fnic->fw_ack_recd[i] = 0;
  639. fnic->fw_ack_index[i] = -1;
  640. }
  641. for (i = 0; i < FNIC_IO_LOCKS; i++)
  642. spin_lock_init(&fnic->io_req_lock[i]);
  643. fnic->io_req_pool = mempool_create_slab_pool(2, fnic_io_req_cache);
  644. if (!fnic->io_req_pool)
  645. goto err_out_free_resources;
  646. pool = mempool_create_slab_pool(2, fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]);
  647. if (!pool)
  648. goto err_out_free_ioreq_pool;
  649. fnic->io_sgl_pool[FNIC_SGL_CACHE_DFLT] = pool;
  650. pool = mempool_create_slab_pool(2, fnic_sgl_cache[FNIC_SGL_CACHE_MAX]);
  651. if (!pool)
  652. goto err_out_free_dflt_pool;
  653. fnic->io_sgl_pool[FNIC_SGL_CACHE_MAX] = pool;
  654. /* setup vlan config, hw inserts vlan header */
  655. fnic->vlan_hw_insert = 1;
  656. fnic->vlan_id = 0;
  657. /* Initialize the FIP fcoe_ctrl struct */
  658. fnic->ctlr.send = fnic_eth_send;
  659. fnic->ctlr.update_mac = fnic_update_mac;
  660. fnic->ctlr.get_src_addr = fnic_get_mac;
  661. if (fnic->config.flags & VFCF_FIP_CAPABLE) {
  662. shost_printk(KERN_INFO, fnic->lport->host,
  663. "firmware supports FIP\n");
  664. /* enable directed and multicast */
  665. vnic_dev_packet_filter(fnic->vdev, 1, 1, 0, 0, 0);
  666. vnic_dev_add_addr(fnic->vdev, FIP_ALL_ENODE_MACS);
  667. vnic_dev_add_addr(fnic->vdev, fnic->ctlr.ctl_src_addr);
  668. fnic->set_vlan = fnic_set_vlan;
  669. fcoe_ctlr_init(&fnic->ctlr, FIP_MODE_AUTO);
  670. setup_timer(&fnic->fip_timer, fnic_fip_notify_timer,
  671. (unsigned long)fnic);
  672. spin_lock_init(&fnic->vlans_lock);
  673. INIT_WORK(&fnic->fip_frame_work, fnic_handle_fip_frame);
  674. INIT_WORK(&fnic->event_work, fnic_handle_event);
  675. skb_queue_head_init(&fnic->fip_frame_queue);
  676. INIT_LIST_HEAD(&fnic->evlist);
  677. INIT_LIST_HEAD(&fnic->vlans);
  678. } else {
  679. shost_printk(KERN_INFO, fnic->lport->host,
  680. "firmware uses non-FIP mode\n");
  681. fcoe_ctlr_init(&fnic->ctlr, FIP_MODE_NON_FIP);
  682. fnic->ctlr.state = FIP_ST_NON_FIP;
  683. }
  684. fnic->state = FNIC_IN_FC_MODE;
  685. atomic_set(&fnic->in_flight, 0);
  686. fnic->state_flags = FNIC_FLAGS_NONE;
  687. /* Enable hardware stripping of vlan header on ingress */
  688. fnic_set_nic_config(fnic, 0, 0, 0, 0, 0, 0, 1);
  689. /* Setup notification buffer area */
  690. err = fnic_notify_set(fnic);
  691. if (err) {
  692. shost_printk(KERN_ERR, fnic->lport->host,
  693. "Failed to alloc notify buffer, aborting.\n");
  694. goto err_out_free_max_pool;
  695. }
  696. /* Setup notify timer when using MSI interrupts */
  697. if (vnic_dev_get_intr_mode(fnic->vdev) == VNIC_DEV_INTR_MODE_MSI)
  698. setup_timer(&fnic->notify_timer,
  699. fnic_notify_timer, (unsigned long)fnic);
  700. /* allocate RQ buffers and post them to RQ*/
  701. for (i = 0; i < fnic->rq_count; i++) {
  702. err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame);
  703. if (err) {
  704. shost_printk(KERN_ERR, fnic->lport->host,
  705. "fnic_alloc_rq_frame can't alloc "
  706. "frame\n");
  707. goto err_out_free_rq_buf;
  708. }
  709. }
  710. /*
  711. * Initialization done with PCI system, hardware, firmware.
  712. * Add host to SCSI
  713. */
  714. err = scsi_add_host(lp->host, &pdev->dev);
  715. if (err) {
  716. shost_printk(KERN_ERR, fnic->lport->host,
  717. "fnic: scsi_add_host failed...exiting\n");
  718. goto err_out_free_rq_buf;
  719. }
  720. /* Start local port initiatialization */
  721. lp->link_up = 0;
  722. lp->max_retry_count = fnic->config.flogi_retries;
  723. lp->max_rport_retry_count = fnic->config.plogi_retries;
  724. lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
  725. FCP_SPPF_CONF_COMPL);
  726. if (fnic->config.flags & VFCF_FCP_SEQ_LVL_ERR)
  727. lp->service_params |= FCP_SPPF_RETRY;
  728. lp->boot_time = jiffies;
  729. lp->e_d_tov = fnic->config.ed_tov;
  730. lp->r_a_tov = fnic->config.ra_tov;
  731. lp->link_supported_speeds = FC_PORTSPEED_10GBIT;
  732. fc_set_wwnn(lp, fnic->config.node_wwn);
  733. fc_set_wwpn(lp, fnic->config.port_wwn);
  734. fcoe_libfc_config(lp, &fnic->ctlr, &fnic_transport_template, 0);
  735. if (!fc_exch_mgr_alloc(lp, FC_CLASS_3, FCPIO_HOST_EXCH_RANGE_START,
  736. FCPIO_HOST_EXCH_RANGE_END, NULL)) {
  737. err = -ENOMEM;
  738. goto err_out_remove_scsi_host;
  739. }
  740. fc_lport_init_stats(lp);
  741. fnic->stats_reset_time = jiffies;
  742. fc_lport_config(lp);
  743. if (fc_set_mfs(lp, fnic->config.maxdatafieldsize +
  744. sizeof(struct fc_frame_header))) {
  745. err = -EINVAL;
  746. goto err_out_free_exch_mgr;
  747. }
  748. fc_host_maxframe_size(lp->host) = lp->mfs;
  749. fc_host_dev_loss_tmo(lp->host) = fnic->config.port_down_timeout / 1000;
  750. sprintf(fc_host_symbolic_name(lp->host),
  751. DRV_NAME " v" DRV_VERSION " over %s", fnic->name);
  752. spin_lock_irqsave(&fnic_list_lock, flags);
  753. list_add_tail(&fnic->list, &fnic_list);
  754. spin_unlock_irqrestore(&fnic_list_lock, flags);
  755. INIT_WORK(&fnic->link_work, fnic_handle_link);
  756. INIT_WORK(&fnic->frame_work, fnic_handle_frame);
  757. skb_queue_head_init(&fnic->frame_queue);
  758. skb_queue_head_init(&fnic->tx_queue);
  759. /* Enable all queues */
  760. for (i = 0; i < fnic->raw_wq_count; i++)
  761. vnic_wq_enable(&fnic->wq[i]);
  762. for (i = 0; i < fnic->rq_count; i++)
  763. vnic_rq_enable(&fnic->rq[i]);
  764. for (i = 0; i < fnic->wq_copy_count; i++)
  765. vnic_wq_copy_enable(&fnic->wq_copy[i]);
  766. fc_fabric_login(lp);
  767. vnic_dev_enable(fnic->vdev);
  768. err = fnic_request_intr(fnic);
  769. if (err) {
  770. shost_printk(KERN_ERR, fnic->lport->host,
  771. "Unable to request irq.\n");
  772. goto err_out_free_exch_mgr;
  773. }
  774. for (i = 0; i < fnic->intr_count; i++)
  775. vnic_intr_unmask(&fnic->intr[i]);
  776. fnic_notify_timer_start(fnic);
  777. return 0;
  778. err_out_free_exch_mgr:
  779. fc_exch_mgr_free(lp);
  780. err_out_remove_scsi_host:
  781. fc_remove_host(lp->host);
  782. scsi_remove_host(lp->host);
  783. err_out_free_rq_buf:
  784. for (i = 0; i < fnic->rq_count; i++)
  785. vnic_rq_clean(&fnic->rq[i], fnic_free_rq_buf);
  786. vnic_dev_notify_unset(fnic->vdev);
  787. err_out_free_max_pool:
  788. mempool_destroy(fnic->io_sgl_pool[FNIC_SGL_CACHE_MAX]);
  789. err_out_free_dflt_pool:
  790. mempool_destroy(fnic->io_sgl_pool[FNIC_SGL_CACHE_DFLT]);
  791. err_out_free_ioreq_pool:
  792. mempool_destroy(fnic->io_req_pool);
  793. err_out_free_resources:
  794. fnic_free_vnic_resources(fnic);
  795. err_out_clear_intr:
  796. fnic_clear_intr_mode(fnic);
  797. err_out_dev_close:
  798. vnic_dev_close(fnic->vdev);
  799. err_out_vnic_unregister:
  800. vnic_dev_unregister(fnic->vdev);
  801. err_out_iounmap:
  802. fnic_iounmap(fnic);
  803. err_out_release_regions:
  804. pci_release_regions(pdev);
  805. err_out_disable_device:
  806. pci_disable_device(pdev);
  807. err_out_free_hba:
  808. fnic_stats_debugfs_remove(fnic);
  809. scsi_host_put(lp->host);
  810. err_out:
  811. return err;
  812. }
  813. static void fnic_remove(struct pci_dev *pdev)
  814. {
  815. struct fnic *fnic = pci_get_drvdata(pdev);
  816. struct fc_lport *lp = fnic->lport;
  817. unsigned long flags;
  818. /*
  819. * Mark state so that the workqueue thread stops forwarding
  820. * received frames and link events to the local port. ISR and
  821. * other threads that can queue work items will also stop
  822. * creating work items on the fnic workqueue
  823. */
  824. spin_lock_irqsave(&fnic->fnic_lock, flags);
  825. fnic->stop_rx_link_events = 1;
  826. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  827. if (vnic_dev_get_intr_mode(fnic->vdev) == VNIC_DEV_INTR_MODE_MSI)
  828. del_timer_sync(&fnic->notify_timer);
  829. /*
  830. * Flush the fnic event queue. After this call, there should
  831. * be no event queued for this fnic device in the workqueue
  832. */
  833. flush_workqueue(fnic_event_queue);
  834. skb_queue_purge(&fnic->frame_queue);
  835. skb_queue_purge(&fnic->tx_queue);
  836. if (fnic->config.flags & VFCF_FIP_CAPABLE) {
  837. del_timer_sync(&fnic->fip_timer);
  838. skb_queue_purge(&fnic->fip_frame_queue);
  839. fnic_fcoe_reset_vlans(fnic);
  840. fnic_fcoe_evlist_free(fnic);
  841. }
  842. /*
  843. * Log off the fabric. This stops all remote ports, dns port,
  844. * logs off the fabric. This flushes all rport, disc, lport work
  845. * before returning
  846. */
  847. fc_fabric_logoff(fnic->lport);
  848. spin_lock_irqsave(&fnic->fnic_lock, flags);
  849. fnic->in_remove = 1;
  850. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  851. fcoe_ctlr_destroy(&fnic->ctlr);
  852. fc_lport_destroy(lp);
  853. fnic_stats_debugfs_remove(fnic);
  854. /*
  855. * This stops the fnic device, masks all interrupts. Completed
  856. * CQ entries are drained. Posted WQ/RQ/Copy-WQ entries are
  857. * cleaned up
  858. */
  859. fnic_cleanup(fnic);
  860. BUG_ON(!skb_queue_empty(&fnic->frame_queue));
  861. BUG_ON(!skb_queue_empty(&fnic->tx_queue));
  862. spin_lock_irqsave(&fnic_list_lock, flags);
  863. list_del(&fnic->list);
  864. spin_unlock_irqrestore(&fnic_list_lock, flags);
  865. fc_remove_host(fnic->lport->host);
  866. scsi_remove_host(fnic->lport->host);
  867. fc_exch_mgr_free(fnic->lport);
  868. vnic_dev_notify_unset(fnic->vdev);
  869. fnic_free_intr(fnic);
  870. fnic_free_vnic_resources(fnic);
  871. fnic_clear_intr_mode(fnic);
  872. vnic_dev_close(fnic->vdev);
  873. vnic_dev_unregister(fnic->vdev);
  874. fnic_iounmap(fnic);
  875. pci_release_regions(pdev);
  876. pci_disable_device(pdev);
  877. scsi_host_put(lp->host);
  878. }
  879. static struct pci_driver fnic_driver = {
  880. .name = DRV_NAME,
  881. .id_table = fnic_id_table,
  882. .probe = fnic_probe,
  883. .remove = fnic_remove,
  884. };
  885. static int __init fnic_init_module(void)
  886. {
  887. size_t len;
  888. int err = 0;
  889. printk(KERN_INFO PFX "%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
  890. /* Create debugfs entries for fnic */
  891. err = fnic_debugfs_init();
  892. if (err < 0) {
  893. printk(KERN_ERR PFX "Failed to create fnic directory "
  894. "for tracing and stats logging\n");
  895. fnic_debugfs_terminate();
  896. }
  897. /* Allocate memory for trace buffer */
  898. err = fnic_trace_buf_init();
  899. if (err < 0) {
  900. printk(KERN_ERR PFX
  901. "Trace buffer initialization Failed. "
  902. "Fnic Tracing utility is disabled\n");
  903. fnic_trace_free();
  904. }
  905. /* Allocate memory for fc trace buffer */
  906. err = fnic_fc_trace_init();
  907. if (err < 0) {
  908. printk(KERN_ERR PFX "FC trace buffer initialization Failed "
  909. "FC frame tracing utility is disabled\n");
  910. fnic_fc_trace_free();
  911. }
  912. /* Create a cache for allocation of default size sgls */
  913. len = sizeof(struct fnic_dflt_sgl_list);
  914. fnic_sgl_cache[FNIC_SGL_CACHE_DFLT] = kmem_cache_create
  915. ("fnic_sgl_dflt", len + FNIC_SG_DESC_ALIGN, FNIC_SG_DESC_ALIGN,
  916. SLAB_HWCACHE_ALIGN,
  917. NULL);
  918. if (!fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]) {
  919. printk(KERN_ERR PFX "failed to create fnic dflt sgl slab\n");
  920. err = -ENOMEM;
  921. goto err_create_fnic_sgl_slab_dflt;
  922. }
  923. /* Create a cache for allocation of max size sgls*/
  924. len = sizeof(struct fnic_sgl_list);
  925. fnic_sgl_cache[FNIC_SGL_CACHE_MAX] = kmem_cache_create
  926. ("fnic_sgl_max", len + FNIC_SG_DESC_ALIGN, FNIC_SG_DESC_ALIGN,
  927. SLAB_HWCACHE_ALIGN,
  928. NULL);
  929. if (!fnic_sgl_cache[FNIC_SGL_CACHE_MAX]) {
  930. printk(KERN_ERR PFX "failed to create fnic max sgl slab\n");
  931. err = -ENOMEM;
  932. goto err_create_fnic_sgl_slab_max;
  933. }
  934. /* Create a cache of io_req structs for use via mempool */
  935. fnic_io_req_cache = kmem_cache_create("fnic_io_req",
  936. sizeof(struct fnic_io_req),
  937. 0, SLAB_HWCACHE_ALIGN, NULL);
  938. if (!fnic_io_req_cache) {
  939. printk(KERN_ERR PFX "failed to create fnic io_req slab\n");
  940. err = -ENOMEM;
  941. goto err_create_fnic_ioreq_slab;
  942. }
  943. fnic_event_queue = create_singlethread_workqueue("fnic_event_wq");
  944. if (!fnic_event_queue) {
  945. printk(KERN_ERR PFX "fnic work queue create failed\n");
  946. err = -ENOMEM;
  947. goto err_create_fnic_workq;
  948. }
  949. spin_lock_init(&fnic_list_lock);
  950. INIT_LIST_HEAD(&fnic_list);
  951. fnic_fip_queue = create_singlethread_workqueue("fnic_fip_q");
  952. if (!fnic_fip_queue) {
  953. printk(KERN_ERR PFX "fnic FIP work queue create failed\n");
  954. err = -ENOMEM;
  955. goto err_create_fip_workq;
  956. }
  957. fnic_fc_transport = fc_attach_transport(&fnic_fc_functions);
  958. if (!fnic_fc_transport) {
  959. printk(KERN_ERR PFX "fc_attach_transport error\n");
  960. err = -ENOMEM;
  961. goto err_fc_transport;
  962. }
  963. /* register the driver with PCI system */
  964. err = pci_register_driver(&fnic_driver);
  965. if (err < 0) {
  966. printk(KERN_ERR PFX "pci register error\n");
  967. goto err_pci_register;
  968. }
  969. return err;
  970. err_pci_register:
  971. fc_release_transport(fnic_fc_transport);
  972. err_fc_transport:
  973. destroy_workqueue(fnic_fip_queue);
  974. err_create_fip_workq:
  975. destroy_workqueue(fnic_event_queue);
  976. err_create_fnic_workq:
  977. kmem_cache_destroy(fnic_io_req_cache);
  978. err_create_fnic_ioreq_slab:
  979. kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_MAX]);
  980. err_create_fnic_sgl_slab_max:
  981. kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]);
  982. err_create_fnic_sgl_slab_dflt:
  983. fnic_trace_free();
  984. fnic_fc_trace_free();
  985. fnic_debugfs_terminate();
  986. return err;
  987. }
  988. static void __exit fnic_cleanup_module(void)
  989. {
  990. pci_unregister_driver(&fnic_driver);
  991. destroy_workqueue(fnic_event_queue);
  992. if (fnic_fip_queue) {
  993. flush_workqueue(fnic_fip_queue);
  994. destroy_workqueue(fnic_fip_queue);
  995. }
  996. kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_MAX]);
  997. kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]);
  998. kmem_cache_destroy(fnic_io_req_cache);
  999. fc_release_transport(fnic_fc_transport);
  1000. fnic_trace_free();
  1001. fnic_fc_trace_free();
  1002. fnic_debugfs_terminate();
  1003. }
  1004. module_init(fnic_init_module);
  1005. module_exit(fnic_cleanup_module);