fnic_main.c 31 KB

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