fnic_main.c 32 KB

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