fnic_main.c 32 KB

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