fnic_main.c 32 KB

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