bnx2fc_fcoe.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455
  1. /* bnx2fc_fcoe.c: Broadcom NetXtreme II Linux FCoE offload driver.
  2. * This file contains the code that interacts with libfc, libfcoe,
  3. * cnic modules to create FCoE instances, send/receive non-offloaded
  4. * FIP/FCoE packets, listen to link events etc.
  5. *
  6. * Copyright (c) 2008 - 2010 Broadcom Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation.
  11. *
  12. * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
  13. */
  14. #include "bnx2fc.h"
  15. static struct list_head adapter_list;
  16. static struct list_head if_list;
  17. static u32 adapter_count;
  18. static DEFINE_MUTEX(bnx2fc_dev_lock);
  19. DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
  20. #define DRV_MODULE_NAME "bnx2fc"
  21. #define DRV_MODULE_VERSION BNX2FC_VERSION
  22. #define DRV_MODULE_RELDATE "Jun 10, 2011"
  23. static char version[] __devinitdata =
  24. "Broadcom NetXtreme II FCoE Driver " DRV_MODULE_NAME \
  25. " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  26. MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
  27. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 FCoE Driver");
  28. MODULE_LICENSE("GPL");
  29. MODULE_VERSION(DRV_MODULE_VERSION);
  30. #define BNX2FC_MAX_QUEUE_DEPTH 256
  31. #define BNX2FC_MIN_QUEUE_DEPTH 32
  32. #define FCOE_WORD_TO_BYTE 4
  33. static struct scsi_transport_template *bnx2fc_transport_template;
  34. static struct scsi_transport_template *bnx2fc_vport_xport_template;
  35. struct workqueue_struct *bnx2fc_wq;
  36. /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
  37. * Here the io threads are per cpu but the l2 thread is just one
  38. */
  39. struct fcoe_percpu_s bnx2fc_global;
  40. DEFINE_SPINLOCK(bnx2fc_global_lock);
  41. static struct cnic_ulp_ops bnx2fc_cnic_cb;
  42. static struct libfc_function_template bnx2fc_libfc_fcn_templ;
  43. static struct scsi_host_template bnx2fc_shost_template;
  44. static struct fc_function_template bnx2fc_transport_function;
  45. static struct fc_function_template bnx2fc_vport_xport_function;
  46. static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
  47. static int bnx2fc_destroy(struct net_device *net_device);
  48. static int bnx2fc_enable(struct net_device *netdev);
  49. static int bnx2fc_disable(struct net_device *netdev);
  50. static void bnx2fc_recv_frame(struct sk_buff *skb);
  51. static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
  52. static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
  53. static int bnx2fc_net_config(struct fc_lport *lp);
  54. static int bnx2fc_lport_config(struct fc_lport *lport);
  55. static int bnx2fc_em_config(struct fc_lport *lport);
  56. static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
  57. static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
  58. static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
  59. static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
  60. static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
  61. struct device *parent, int npiv);
  62. static void bnx2fc_destroy_work(struct work_struct *work);
  63. static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
  64. static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
  65. *phys_dev);
  66. static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
  67. static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
  68. static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
  69. static void bnx2fc_port_shutdown(struct fc_lport *lport);
  70. static void bnx2fc_stop(struct bnx2fc_interface *interface);
  71. static int __init bnx2fc_mod_init(void);
  72. static void __exit bnx2fc_mod_exit(void);
  73. unsigned int bnx2fc_debug_level;
  74. module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
  75. static int bnx2fc_cpu_callback(struct notifier_block *nfb,
  76. unsigned long action, void *hcpu);
  77. /* notification function for CPU hotplug events */
  78. static struct notifier_block bnx2fc_cpu_notifier = {
  79. .notifier_call = bnx2fc_cpu_callback,
  80. };
  81. static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
  82. {
  83. struct fcoe_percpu_s *bg;
  84. struct fcoe_rcv_info *fr;
  85. struct sk_buff_head *list;
  86. struct sk_buff *skb, *next;
  87. struct sk_buff *head;
  88. bg = &bnx2fc_global;
  89. spin_lock_bh(&bg->fcoe_rx_list.lock);
  90. list = &bg->fcoe_rx_list;
  91. head = list->next;
  92. for (skb = head; skb != (struct sk_buff *)list;
  93. skb = next) {
  94. next = skb->next;
  95. fr = fcoe_dev_from_skb(skb);
  96. if (fr->fr_dev == lp) {
  97. __skb_unlink(skb, list);
  98. kfree_skb(skb);
  99. }
  100. }
  101. spin_unlock_bh(&bg->fcoe_rx_list.lock);
  102. }
  103. int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
  104. {
  105. int rc;
  106. spin_lock(&bnx2fc_global_lock);
  107. rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
  108. spin_unlock(&bnx2fc_global_lock);
  109. return rc;
  110. }
  111. static void bnx2fc_abort_io(struct fc_lport *lport)
  112. {
  113. /*
  114. * This function is no-op for bnx2fc, but we do
  115. * not want to leave it as NULL either, as libfc
  116. * can call the default function which is
  117. * fc_fcp_abort_io.
  118. */
  119. }
  120. static void bnx2fc_cleanup(struct fc_lport *lport)
  121. {
  122. struct fcoe_port *port = lport_priv(lport);
  123. struct bnx2fc_interface *interface = port->priv;
  124. struct bnx2fc_hba *hba = interface->hba;
  125. struct bnx2fc_rport *tgt;
  126. int i;
  127. BNX2FC_MISC_DBG("Entered %s\n", __func__);
  128. mutex_lock(&hba->hba_mutex);
  129. spin_lock_bh(&hba->hba_lock);
  130. for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
  131. tgt = hba->tgt_ofld_list[i];
  132. if (tgt) {
  133. /* Cleanup IOs belonging to requested vport */
  134. if (tgt->port == port) {
  135. spin_unlock_bh(&hba->hba_lock);
  136. BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
  137. bnx2fc_flush_active_ios(tgt);
  138. spin_lock_bh(&hba->hba_lock);
  139. }
  140. }
  141. }
  142. spin_unlock_bh(&hba->hba_lock);
  143. mutex_unlock(&hba->hba_mutex);
  144. }
  145. static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
  146. struct fc_frame *fp)
  147. {
  148. struct fc_rport_priv *rdata = tgt->rdata;
  149. struct fc_frame_header *fh;
  150. int rc = 0;
  151. fh = fc_frame_header_get(fp);
  152. BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
  153. "r_ctl = 0x%x\n", rdata->ids.port_id,
  154. ntohs(fh->fh_ox_id), fh->fh_r_ctl);
  155. if ((fh->fh_type == FC_TYPE_ELS) &&
  156. (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
  157. switch (fc_frame_payload_op(fp)) {
  158. case ELS_ADISC:
  159. rc = bnx2fc_send_adisc(tgt, fp);
  160. break;
  161. case ELS_LOGO:
  162. rc = bnx2fc_send_logo(tgt, fp);
  163. break;
  164. case ELS_RLS:
  165. rc = bnx2fc_send_rls(tgt, fp);
  166. break;
  167. default:
  168. break;
  169. }
  170. } else if ((fh->fh_type == FC_TYPE_BLS) &&
  171. (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
  172. BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
  173. else {
  174. BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
  175. "rctl 0x%x thru non-offload path\n",
  176. fh->fh_type, fh->fh_r_ctl);
  177. return -ENODEV;
  178. }
  179. if (rc)
  180. return -ENOMEM;
  181. else
  182. return 0;
  183. }
  184. /**
  185. * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
  186. *
  187. * @lport: the associated local port
  188. * @fp: the fc_frame to be transmitted
  189. */
  190. static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
  191. {
  192. struct ethhdr *eh;
  193. struct fcoe_crc_eof *cp;
  194. struct sk_buff *skb;
  195. struct fc_frame_header *fh;
  196. struct bnx2fc_interface *interface;
  197. struct bnx2fc_hba *hba;
  198. struct fcoe_port *port;
  199. struct fcoe_hdr *hp;
  200. struct bnx2fc_rport *tgt;
  201. struct fcoe_dev_stats *stats;
  202. u8 sof, eof;
  203. u32 crc;
  204. unsigned int hlen, tlen, elen;
  205. int wlen, rc = 0;
  206. port = (struct fcoe_port *)lport_priv(lport);
  207. interface = port->priv;
  208. hba = interface->hba;
  209. fh = fc_frame_header_get(fp);
  210. skb = fp_skb(fp);
  211. if (!lport->link_up) {
  212. BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
  213. kfree_skb(skb);
  214. return 0;
  215. }
  216. if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
  217. if (!interface->ctlr.sel_fcf) {
  218. BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
  219. kfree_skb(skb);
  220. return -EINVAL;
  221. }
  222. if (fcoe_ctlr_els_send(&interface->ctlr, lport, skb))
  223. return 0;
  224. }
  225. sof = fr_sof(fp);
  226. eof = fr_eof(fp);
  227. /*
  228. * Snoop the frame header to check if the frame is for
  229. * an offloaded session
  230. */
  231. /*
  232. * tgt_ofld_list access is synchronized using
  233. * both hba mutex and hba lock. Atleast hba mutex or
  234. * hba lock needs to be held for read access.
  235. */
  236. spin_lock_bh(&hba->hba_lock);
  237. tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
  238. if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
  239. /* This frame is for offloaded session */
  240. BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
  241. "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
  242. spin_unlock_bh(&hba->hba_lock);
  243. rc = bnx2fc_xmit_l2_frame(tgt, fp);
  244. if (rc != -ENODEV) {
  245. kfree_skb(skb);
  246. return rc;
  247. }
  248. } else {
  249. spin_unlock_bh(&hba->hba_lock);
  250. }
  251. elen = sizeof(struct ethhdr);
  252. hlen = sizeof(struct fcoe_hdr);
  253. tlen = sizeof(struct fcoe_crc_eof);
  254. wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
  255. skb->ip_summed = CHECKSUM_NONE;
  256. crc = fcoe_fc_crc(fp);
  257. /* copy port crc and eof to the skb buff */
  258. if (skb_is_nonlinear(skb)) {
  259. skb_frag_t *frag;
  260. if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
  261. kfree_skb(skb);
  262. return -ENOMEM;
  263. }
  264. frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
  265. cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
  266. + frag->page_offset;
  267. } else {
  268. cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
  269. }
  270. memset(cp, 0, sizeof(*cp));
  271. cp->fcoe_eof = eof;
  272. cp->fcoe_crc32 = cpu_to_le32(~crc);
  273. if (skb_is_nonlinear(skb)) {
  274. kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
  275. cp = NULL;
  276. }
  277. /* adjust skb network/transport offsets to match mac/fcoe/port */
  278. skb_push(skb, elen + hlen);
  279. skb_reset_mac_header(skb);
  280. skb_reset_network_header(skb);
  281. skb->mac_len = elen;
  282. skb->protocol = htons(ETH_P_FCOE);
  283. skb->dev = interface->netdev;
  284. /* fill up mac and fcoe headers */
  285. eh = eth_hdr(skb);
  286. eh->h_proto = htons(ETH_P_FCOE);
  287. if (interface->ctlr.map_dest)
  288. fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
  289. else
  290. /* insert GW address */
  291. memcpy(eh->h_dest, interface->ctlr.dest_addr, ETH_ALEN);
  292. if (unlikely(interface->ctlr.flogi_oxid != FC_XID_UNKNOWN))
  293. memcpy(eh->h_source, interface->ctlr.ctl_src_addr, ETH_ALEN);
  294. else
  295. memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
  296. hp = (struct fcoe_hdr *)(eh + 1);
  297. memset(hp, 0, sizeof(*hp));
  298. if (FC_FCOE_VER)
  299. FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
  300. hp->fcoe_sof = sof;
  301. /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
  302. if (lport->seq_offload && fr_max_payload(fp)) {
  303. skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
  304. skb_shinfo(skb)->gso_size = fr_max_payload(fp);
  305. } else {
  306. skb_shinfo(skb)->gso_type = 0;
  307. skb_shinfo(skb)->gso_size = 0;
  308. }
  309. /*update tx stats */
  310. stats = per_cpu_ptr(lport->dev_stats, get_cpu());
  311. stats->TxFrames++;
  312. stats->TxWords += wlen;
  313. put_cpu();
  314. /* send down to lld */
  315. fr_dev(fp) = lport;
  316. if (port->fcoe_pending_queue.qlen)
  317. fcoe_check_wait_queue(lport, skb);
  318. else if (fcoe_start_io(skb))
  319. fcoe_check_wait_queue(lport, skb);
  320. return 0;
  321. }
  322. /**
  323. * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
  324. *
  325. * @skb: the receive socket buffer
  326. * @dev: associated net device
  327. * @ptype: context
  328. * @olddev: last device
  329. *
  330. * This function receives the packet and builds FC frame and passes it up
  331. */
  332. static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
  333. struct packet_type *ptype, struct net_device *olddev)
  334. {
  335. struct fc_lport *lport;
  336. struct bnx2fc_interface *interface;
  337. struct fc_frame_header *fh;
  338. struct fcoe_rcv_info *fr;
  339. struct fcoe_percpu_s *bg;
  340. unsigned short oxid;
  341. interface = container_of(ptype, struct bnx2fc_interface,
  342. fcoe_packet_type);
  343. lport = interface->ctlr.lp;
  344. if (unlikely(lport == NULL)) {
  345. printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
  346. goto err;
  347. }
  348. if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
  349. printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
  350. goto err;
  351. }
  352. /*
  353. * Check for minimum frame length, and make sure required FCoE
  354. * and FC headers are pulled into the linear data area.
  355. */
  356. if (unlikely((skb->len < FCOE_MIN_FRAME) ||
  357. !pskb_may_pull(skb, FCOE_HEADER_LEN)))
  358. goto err;
  359. skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
  360. fh = (struct fc_frame_header *) skb_transport_header(skb);
  361. oxid = ntohs(fh->fh_ox_id);
  362. fr = fcoe_dev_from_skb(skb);
  363. fr->fr_dev = lport;
  364. fr->ptype = ptype;
  365. bg = &bnx2fc_global;
  366. spin_lock_bh(&bg->fcoe_rx_list.lock);
  367. __skb_queue_tail(&bg->fcoe_rx_list, skb);
  368. if (bg->fcoe_rx_list.qlen == 1)
  369. wake_up_process(bg->thread);
  370. spin_unlock_bh(&bg->fcoe_rx_list.lock);
  371. return 0;
  372. err:
  373. kfree_skb(skb);
  374. return -1;
  375. }
  376. static int bnx2fc_l2_rcv_thread(void *arg)
  377. {
  378. struct fcoe_percpu_s *bg = arg;
  379. struct sk_buff *skb;
  380. set_user_nice(current, -20);
  381. set_current_state(TASK_INTERRUPTIBLE);
  382. while (!kthread_should_stop()) {
  383. schedule();
  384. spin_lock_bh(&bg->fcoe_rx_list.lock);
  385. while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
  386. spin_unlock_bh(&bg->fcoe_rx_list.lock);
  387. bnx2fc_recv_frame(skb);
  388. spin_lock_bh(&bg->fcoe_rx_list.lock);
  389. }
  390. __set_current_state(TASK_INTERRUPTIBLE);
  391. spin_unlock_bh(&bg->fcoe_rx_list.lock);
  392. }
  393. __set_current_state(TASK_RUNNING);
  394. return 0;
  395. }
  396. static void bnx2fc_recv_frame(struct sk_buff *skb)
  397. {
  398. u32 fr_len;
  399. struct fc_lport *lport;
  400. struct fcoe_rcv_info *fr;
  401. struct fcoe_dev_stats *stats;
  402. struct fc_frame_header *fh;
  403. struct fcoe_crc_eof crc_eof;
  404. struct fc_frame *fp;
  405. struct fc_lport *vn_port;
  406. struct fcoe_port *port;
  407. u8 *mac = NULL;
  408. u8 *dest_mac = NULL;
  409. struct fcoe_hdr *hp;
  410. fr = fcoe_dev_from_skb(skb);
  411. lport = fr->fr_dev;
  412. if (unlikely(lport == NULL)) {
  413. printk(KERN_ERR PFX "Invalid lport struct\n");
  414. kfree_skb(skb);
  415. return;
  416. }
  417. if (skb_is_nonlinear(skb))
  418. skb_linearize(skb);
  419. mac = eth_hdr(skb)->h_source;
  420. dest_mac = eth_hdr(skb)->h_dest;
  421. /* Pull the header */
  422. hp = (struct fcoe_hdr *) skb_network_header(skb);
  423. fh = (struct fc_frame_header *) skb_transport_header(skb);
  424. skb_pull(skb, sizeof(struct fcoe_hdr));
  425. fr_len = skb->len - sizeof(struct fcoe_crc_eof);
  426. stats = per_cpu_ptr(lport->dev_stats, get_cpu());
  427. stats->RxFrames++;
  428. stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
  429. fp = (struct fc_frame *)skb;
  430. fc_frame_init(fp);
  431. fr_dev(fp) = lport;
  432. fr_sof(fp) = hp->fcoe_sof;
  433. if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
  434. put_cpu();
  435. kfree_skb(skb);
  436. return;
  437. }
  438. fr_eof(fp) = crc_eof.fcoe_eof;
  439. fr_crc(fp) = crc_eof.fcoe_crc32;
  440. if (pskb_trim(skb, fr_len)) {
  441. put_cpu();
  442. kfree_skb(skb);
  443. return;
  444. }
  445. fh = fc_frame_header_get(fp);
  446. vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
  447. if (vn_port) {
  448. port = lport_priv(vn_port);
  449. if (compare_ether_addr(port->data_src_addr, dest_mac)
  450. != 0) {
  451. BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
  452. put_cpu();
  453. kfree_skb(skb);
  454. return;
  455. }
  456. }
  457. if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
  458. fh->fh_type == FC_TYPE_FCP) {
  459. /* Drop FCP data. We dont this in L2 path */
  460. put_cpu();
  461. kfree_skb(skb);
  462. return;
  463. }
  464. if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
  465. fh->fh_type == FC_TYPE_ELS) {
  466. switch (fc_frame_payload_op(fp)) {
  467. case ELS_LOGO:
  468. if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
  469. /* drop non-FIP LOGO */
  470. put_cpu();
  471. kfree_skb(skb);
  472. return;
  473. }
  474. break;
  475. }
  476. }
  477. if (le32_to_cpu(fr_crc(fp)) !=
  478. ~crc32(~0, skb->data, fr_len)) {
  479. if (stats->InvalidCRCCount < 5)
  480. printk(KERN_WARNING PFX "dropping frame with "
  481. "CRC error\n");
  482. stats->InvalidCRCCount++;
  483. put_cpu();
  484. kfree_skb(skb);
  485. return;
  486. }
  487. put_cpu();
  488. fc_exch_recv(lport, fp);
  489. }
  490. /**
  491. * bnx2fc_percpu_io_thread - thread per cpu for ios
  492. *
  493. * @arg: ptr to bnx2fc_percpu_info structure
  494. */
  495. int bnx2fc_percpu_io_thread(void *arg)
  496. {
  497. struct bnx2fc_percpu_s *p = arg;
  498. struct bnx2fc_work *work, *tmp;
  499. LIST_HEAD(work_list);
  500. set_user_nice(current, -20);
  501. set_current_state(TASK_INTERRUPTIBLE);
  502. while (!kthread_should_stop()) {
  503. schedule();
  504. spin_lock_bh(&p->fp_work_lock);
  505. while (!list_empty(&p->work_list)) {
  506. list_splice_init(&p->work_list, &work_list);
  507. spin_unlock_bh(&p->fp_work_lock);
  508. list_for_each_entry_safe(work, tmp, &work_list, list) {
  509. list_del_init(&work->list);
  510. bnx2fc_process_cq_compl(work->tgt, work->wqe);
  511. kfree(work);
  512. }
  513. spin_lock_bh(&p->fp_work_lock);
  514. }
  515. __set_current_state(TASK_INTERRUPTIBLE);
  516. spin_unlock_bh(&p->fp_work_lock);
  517. }
  518. __set_current_state(TASK_RUNNING);
  519. return 0;
  520. }
  521. static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
  522. {
  523. struct fc_host_statistics *bnx2fc_stats;
  524. struct fc_lport *lport = shost_priv(shost);
  525. struct fcoe_port *port = lport_priv(lport);
  526. struct bnx2fc_interface *interface = port->priv;
  527. struct bnx2fc_hba *hba = interface->hba;
  528. struct fcoe_statistics_params *fw_stats;
  529. int rc = 0;
  530. fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
  531. if (!fw_stats)
  532. return NULL;
  533. bnx2fc_stats = fc_get_host_stats(shost);
  534. init_completion(&hba->stat_req_done);
  535. if (bnx2fc_send_stat_req(hba))
  536. return bnx2fc_stats;
  537. rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
  538. if (!rc) {
  539. BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
  540. return bnx2fc_stats;
  541. }
  542. bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat2.fc_crc_cnt;
  543. bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt;
  544. bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4;
  545. bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt;
  546. bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4;
  547. bnx2fc_stats->dumped_frames = 0;
  548. bnx2fc_stats->lip_count = 0;
  549. bnx2fc_stats->nos_count = 0;
  550. bnx2fc_stats->loss_of_sync_count = 0;
  551. bnx2fc_stats->loss_of_signal_count = 0;
  552. bnx2fc_stats->prim_seq_protocol_err_count = 0;
  553. return bnx2fc_stats;
  554. }
  555. static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
  556. {
  557. struct fcoe_port *port = lport_priv(lport);
  558. struct bnx2fc_interface *interface = port->priv;
  559. struct Scsi_Host *shost = lport->host;
  560. int rc = 0;
  561. shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
  562. shost->max_lun = BNX2FC_MAX_LUN;
  563. shost->max_id = BNX2FC_MAX_FCP_TGT;
  564. shost->max_channel = 0;
  565. if (lport->vport)
  566. shost->transportt = bnx2fc_vport_xport_template;
  567. else
  568. shost->transportt = bnx2fc_transport_template;
  569. /* Add the new host to SCSI-ml */
  570. rc = scsi_add_host(lport->host, dev);
  571. if (rc) {
  572. printk(KERN_ERR PFX "Error on scsi_add_host\n");
  573. return rc;
  574. }
  575. if (!lport->vport)
  576. fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
  577. sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
  578. BNX2FC_NAME, BNX2FC_VERSION,
  579. interface->netdev->name);
  580. return 0;
  581. }
  582. static void bnx2fc_link_speed_update(struct fc_lport *lport)
  583. {
  584. struct fcoe_port *port = lport_priv(lport);
  585. struct bnx2fc_interface *interface = port->priv;
  586. struct net_device *netdev = interface->netdev;
  587. struct ethtool_cmd ecmd;
  588. if (!dev_ethtool_get_settings(netdev, &ecmd)) {
  589. lport->link_supported_speeds &=
  590. ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
  591. if (ecmd.supported & (SUPPORTED_1000baseT_Half |
  592. SUPPORTED_1000baseT_Full))
  593. lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
  594. if (ecmd.supported & SUPPORTED_10000baseT_Full)
  595. lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
  596. switch (ethtool_cmd_speed(&ecmd)) {
  597. case SPEED_1000:
  598. lport->link_speed = FC_PORTSPEED_1GBIT;
  599. break;
  600. case SPEED_2500:
  601. lport->link_speed = FC_PORTSPEED_2GBIT;
  602. break;
  603. case SPEED_10000:
  604. lport->link_speed = FC_PORTSPEED_10GBIT;
  605. break;
  606. }
  607. }
  608. }
  609. static int bnx2fc_link_ok(struct fc_lport *lport)
  610. {
  611. struct fcoe_port *port = lport_priv(lport);
  612. struct bnx2fc_interface *interface = port->priv;
  613. struct bnx2fc_hba *hba = interface->hba;
  614. struct net_device *dev = hba->phys_dev;
  615. int rc = 0;
  616. if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
  617. clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  618. else {
  619. set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  620. rc = -1;
  621. }
  622. return rc;
  623. }
  624. /**
  625. * bnx2fc_get_link_state - get network link state
  626. *
  627. * @hba: adapter instance pointer
  628. *
  629. * updates adapter structure flag based on netdev state
  630. */
  631. void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
  632. {
  633. if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
  634. set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  635. else
  636. clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  637. }
  638. static int bnx2fc_net_config(struct fc_lport *lport)
  639. {
  640. struct bnx2fc_hba *hba;
  641. struct bnx2fc_interface *interface;
  642. struct fcoe_port *port;
  643. u64 wwnn, wwpn;
  644. port = lport_priv(lport);
  645. interface = port->priv;
  646. hba = interface->hba;
  647. /* require support for get_pauseparam ethtool op. */
  648. if (!hba->phys_dev->ethtool_ops ||
  649. !hba->phys_dev->ethtool_ops->get_pauseparam)
  650. return -EOPNOTSUPP;
  651. if (fc_set_mfs(lport, BNX2FC_MFS))
  652. return -EINVAL;
  653. skb_queue_head_init(&port->fcoe_pending_queue);
  654. port->fcoe_pending_queue_active = 0;
  655. setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
  656. bnx2fc_link_speed_update(lport);
  657. if (!lport->vport) {
  658. wwnn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 1, 0);
  659. BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
  660. fc_set_wwnn(lport, wwnn);
  661. wwpn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 2, 0);
  662. BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
  663. fc_set_wwpn(lport, wwpn);
  664. }
  665. return 0;
  666. }
  667. static void bnx2fc_destroy_timer(unsigned long data)
  668. {
  669. struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
  670. BNX2FC_MISC_DBG("ERROR:bnx2fc_destroy_timer - "
  671. "Destroy compl not received!!\n");
  672. set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
  673. wake_up_interruptible(&hba->destroy_wait);
  674. }
  675. /**
  676. * bnx2fc_indicate_netevent - Generic netdev event handler
  677. *
  678. * @context: adapter structure pointer
  679. * @event: event type
  680. * @vlan_id: vlan id - associated vlan id with this event
  681. *
  682. * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
  683. * NETDEV_CHANGE_MTU events
  684. */
  685. static void bnx2fc_indicate_netevent(void *context, unsigned long event,
  686. u16 vlan_id)
  687. {
  688. struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
  689. struct fc_lport *lport;
  690. struct fc_lport *vport;
  691. struct bnx2fc_interface *interface;
  692. int wait_for_upload = 0;
  693. u32 link_possible = 1;
  694. /* Ignore vlans for now */
  695. if (vlan_id != 0)
  696. return;
  697. switch (event) {
  698. case NETDEV_UP:
  699. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
  700. printk(KERN_ERR "indicate_netevent: "\
  701. "hba is not UP!!\n");
  702. break;
  703. case NETDEV_DOWN:
  704. clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  705. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  706. link_possible = 0;
  707. break;
  708. case NETDEV_GOING_DOWN:
  709. set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  710. link_possible = 0;
  711. break;
  712. case NETDEV_CHANGE:
  713. break;
  714. default:
  715. printk(KERN_ERR PFX "Unkonwn netevent %ld", event);
  716. return;
  717. }
  718. mutex_lock(&bnx2fc_dev_lock);
  719. list_for_each_entry(interface, &if_list, list) {
  720. if (interface->hba != hba)
  721. continue;
  722. lport = interface->ctlr.lp;
  723. BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
  724. interface->netdev->name, event);
  725. bnx2fc_link_speed_update(lport);
  726. if (link_possible && !bnx2fc_link_ok(lport)) {
  727. printk(KERN_ERR "indicate_netevent: ctlr_link_up\n");
  728. fcoe_ctlr_link_up(&interface->ctlr);
  729. } else if (fcoe_ctlr_link_down(&interface->ctlr)) {
  730. mutex_lock(&lport->lp_mutex);
  731. list_for_each_entry(vport, &lport->vports, list)
  732. fc_host_port_type(vport->host) =
  733. FC_PORTTYPE_UNKNOWN;
  734. mutex_unlock(&lport->lp_mutex);
  735. fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
  736. per_cpu_ptr(lport->dev_stats,
  737. get_cpu())->LinkFailureCount++;
  738. put_cpu();
  739. fcoe_clean_pending_queue(lport);
  740. wait_for_upload = 1;
  741. }
  742. }
  743. mutex_unlock(&bnx2fc_dev_lock);
  744. if (wait_for_upload) {
  745. clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
  746. init_waitqueue_head(&hba->shutdown_wait);
  747. BNX2FC_MISC_DBG("indicate_netevent "
  748. "num_ofld_sess = %d\n",
  749. hba->num_ofld_sess);
  750. hba->wait_for_link_down = 1;
  751. wait_event_interruptible(hba->shutdown_wait,
  752. (hba->num_ofld_sess == 0));
  753. BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
  754. hba->num_ofld_sess);
  755. hba->wait_for_link_down = 0;
  756. if (signal_pending(current))
  757. flush_signals(current);
  758. }
  759. }
  760. static int bnx2fc_libfc_config(struct fc_lport *lport)
  761. {
  762. /* Set the function pointers set by bnx2fc driver */
  763. memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
  764. sizeof(struct libfc_function_template));
  765. fc_elsct_init(lport);
  766. fc_exch_init(lport);
  767. fc_rport_init(lport);
  768. fc_disc_init(lport);
  769. return 0;
  770. }
  771. static int bnx2fc_em_config(struct fc_lport *lport)
  772. {
  773. if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
  774. FCOE_MAX_XID, NULL)) {
  775. printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
  776. return -ENOMEM;
  777. }
  778. return 0;
  779. }
  780. static int bnx2fc_lport_config(struct fc_lport *lport)
  781. {
  782. lport->link_up = 0;
  783. lport->qfull = 0;
  784. lport->max_retry_count = 3;
  785. lport->max_rport_retry_count = 3;
  786. lport->e_d_tov = 2 * 1000;
  787. lport->r_a_tov = 10 * 1000;
  788. lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
  789. FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
  790. lport->does_npiv = 1;
  791. memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
  792. lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
  793. /* alloc stats structure */
  794. if (fc_lport_init_stats(lport))
  795. return -ENOMEM;
  796. /* Finish fc_lport configuration */
  797. fc_lport_config(lport);
  798. return 0;
  799. }
  800. /**
  801. * bnx2fc_fip_recv - handle a received FIP frame.
  802. *
  803. * @skb: the received skb
  804. * @dev: associated &net_device
  805. * @ptype: the &packet_type structure which was used to register this handler.
  806. * @orig_dev: original receive &net_device, in case @ dev is a bond.
  807. *
  808. * Returns: 0 for success
  809. */
  810. static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
  811. struct packet_type *ptype,
  812. struct net_device *orig_dev)
  813. {
  814. struct bnx2fc_interface *interface;
  815. interface = container_of(ptype, struct bnx2fc_interface,
  816. fip_packet_type);
  817. fcoe_ctlr_recv(&interface->ctlr, skb);
  818. return 0;
  819. }
  820. /**
  821. * bnx2fc_update_src_mac - Update Ethernet MAC filters.
  822. *
  823. * @fip: FCoE controller.
  824. * @old: Unicast MAC address to delete if the MAC is non-zero.
  825. * @new: Unicast MAC address to add.
  826. *
  827. * Remove any previously-set unicast MAC filter.
  828. * Add secondary FCoE MAC address filter for our OUI.
  829. */
  830. static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
  831. {
  832. struct fcoe_port *port = lport_priv(lport);
  833. memcpy(port->data_src_addr, addr, ETH_ALEN);
  834. }
  835. /**
  836. * bnx2fc_get_src_mac - return the ethernet source address for an lport
  837. *
  838. * @lport: libfc port
  839. */
  840. static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
  841. {
  842. struct fcoe_port *port;
  843. port = (struct fcoe_port *)lport_priv(lport);
  844. return port->data_src_addr;
  845. }
  846. /**
  847. * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
  848. *
  849. * @fip: FCoE controller.
  850. * @skb: FIP Packet.
  851. */
  852. static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
  853. {
  854. skb->dev = bnx2fc_from_ctlr(fip)->netdev;
  855. dev_queue_xmit(skb);
  856. }
  857. static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
  858. {
  859. struct Scsi_Host *shost = vport_to_shost(vport);
  860. struct fc_lport *n_port = shost_priv(shost);
  861. struct fcoe_port *port = lport_priv(n_port);
  862. struct bnx2fc_interface *interface = port->priv;
  863. struct net_device *netdev = interface->netdev;
  864. struct fc_lport *vn_port;
  865. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
  866. printk(KERN_ERR PFX "vn ports cannot be created on"
  867. "this interface\n");
  868. return -EIO;
  869. }
  870. mutex_lock(&bnx2fc_dev_lock);
  871. vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
  872. mutex_unlock(&bnx2fc_dev_lock);
  873. if (IS_ERR(vn_port)) {
  874. printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
  875. netdev->name);
  876. return -EIO;
  877. }
  878. if (disabled) {
  879. fc_vport_set_state(vport, FC_VPORT_DISABLED);
  880. } else {
  881. vn_port->boot_time = jiffies;
  882. fc_lport_init(vn_port);
  883. fc_fabric_login(vn_port);
  884. fc_vport_setlink(vn_port);
  885. }
  886. return 0;
  887. }
  888. static int bnx2fc_vport_destroy(struct fc_vport *vport)
  889. {
  890. struct Scsi_Host *shost = vport_to_shost(vport);
  891. struct fc_lport *n_port = shost_priv(shost);
  892. struct fc_lport *vn_port = vport->dd_data;
  893. struct fcoe_port *port = lport_priv(vn_port);
  894. mutex_lock(&n_port->lp_mutex);
  895. list_del(&vn_port->list);
  896. mutex_unlock(&n_port->lp_mutex);
  897. queue_work(bnx2fc_wq, &port->destroy_work);
  898. return 0;
  899. }
  900. static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
  901. {
  902. struct fc_lport *lport = vport->dd_data;
  903. if (disable) {
  904. fc_vport_set_state(vport, FC_VPORT_DISABLED);
  905. fc_fabric_logoff(lport);
  906. } else {
  907. lport->boot_time = jiffies;
  908. fc_fabric_login(lport);
  909. fc_vport_setlink(lport);
  910. }
  911. return 0;
  912. }
  913. static int bnx2fc_netdev_setup(struct bnx2fc_interface *interface)
  914. {
  915. struct net_device *netdev = interface->netdev;
  916. struct net_device *physdev = interface->hba->phys_dev;
  917. struct netdev_hw_addr *ha;
  918. int sel_san_mac = 0;
  919. /* setup Source MAC Address */
  920. rcu_read_lock();
  921. for_each_dev_addr(physdev, ha) {
  922. BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
  923. ha->type);
  924. printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
  925. ha->addr[1], ha->addr[2], ha->addr[3],
  926. ha->addr[4], ha->addr[5]);
  927. if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
  928. (is_valid_ether_addr(ha->addr))) {
  929. memcpy(interface->ctlr.ctl_src_addr, ha->addr,
  930. ETH_ALEN);
  931. sel_san_mac = 1;
  932. BNX2FC_MISC_DBG("Found SAN MAC\n");
  933. }
  934. }
  935. rcu_read_unlock();
  936. if (!sel_san_mac)
  937. return -ENODEV;
  938. interface->fip_packet_type.func = bnx2fc_fip_recv;
  939. interface->fip_packet_type.type = htons(ETH_P_FIP);
  940. interface->fip_packet_type.dev = netdev;
  941. dev_add_pack(&interface->fip_packet_type);
  942. interface->fcoe_packet_type.func = bnx2fc_rcv;
  943. interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
  944. interface->fcoe_packet_type.dev = netdev;
  945. dev_add_pack(&interface->fcoe_packet_type);
  946. return 0;
  947. }
  948. static int bnx2fc_attach_transport(void)
  949. {
  950. bnx2fc_transport_template =
  951. fc_attach_transport(&bnx2fc_transport_function);
  952. if (bnx2fc_transport_template == NULL) {
  953. printk(KERN_ERR PFX "Failed to attach FC transport\n");
  954. return -ENODEV;
  955. }
  956. bnx2fc_vport_xport_template =
  957. fc_attach_transport(&bnx2fc_vport_xport_function);
  958. if (bnx2fc_vport_xport_template == NULL) {
  959. printk(KERN_ERR PFX
  960. "Failed to attach FC transport for vport\n");
  961. fc_release_transport(bnx2fc_transport_template);
  962. bnx2fc_transport_template = NULL;
  963. return -ENODEV;
  964. }
  965. return 0;
  966. }
  967. static void bnx2fc_release_transport(void)
  968. {
  969. fc_release_transport(bnx2fc_transport_template);
  970. fc_release_transport(bnx2fc_vport_xport_template);
  971. bnx2fc_transport_template = NULL;
  972. bnx2fc_vport_xport_template = NULL;
  973. }
  974. static void bnx2fc_interface_release(struct kref *kref)
  975. {
  976. struct bnx2fc_interface *interface;
  977. struct net_device *netdev;
  978. interface = container_of(kref, struct bnx2fc_interface, kref);
  979. BNX2FC_MISC_DBG("Interface is being released\n");
  980. netdev = interface->netdev;
  981. /* tear-down FIP controller */
  982. if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
  983. fcoe_ctlr_destroy(&interface->ctlr);
  984. kfree(interface);
  985. dev_put(netdev);
  986. module_put(THIS_MODULE);
  987. }
  988. static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
  989. {
  990. kref_get(&interface->kref);
  991. }
  992. static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
  993. {
  994. kref_put(&interface->kref, bnx2fc_interface_release);
  995. }
  996. static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
  997. {
  998. /* Free the command manager */
  999. if (hba->cmd_mgr) {
  1000. bnx2fc_cmd_mgr_free(hba->cmd_mgr);
  1001. hba->cmd_mgr = NULL;
  1002. }
  1003. kfree(hba->tgt_ofld_list);
  1004. bnx2fc_unbind_pcidev(hba);
  1005. kfree(hba);
  1006. }
  1007. /**
  1008. * bnx2fc_hba_create - create a new bnx2fc hba
  1009. *
  1010. * @cnic: pointer to cnic device
  1011. *
  1012. * Creates a new FCoE hba on the given device.
  1013. *
  1014. */
  1015. static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
  1016. {
  1017. struct bnx2fc_hba *hba;
  1018. int rc;
  1019. hba = kzalloc(sizeof(*hba), GFP_KERNEL);
  1020. if (!hba) {
  1021. printk(KERN_ERR PFX "Unable to allocate hba structure\n");
  1022. return NULL;
  1023. }
  1024. spin_lock_init(&hba->hba_lock);
  1025. mutex_init(&hba->hba_mutex);
  1026. hba->cnic = cnic;
  1027. rc = bnx2fc_bind_pcidev(hba);
  1028. if (rc) {
  1029. printk(KERN_ERR PFX "create_adapter: bind error\n");
  1030. goto bind_err;
  1031. }
  1032. hba->phys_dev = cnic->netdev;
  1033. hba->next_conn_id = 0;
  1034. hba->tgt_ofld_list =
  1035. kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
  1036. GFP_KERNEL);
  1037. if (!hba->tgt_ofld_list) {
  1038. printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
  1039. goto tgtofld_err;
  1040. }
  1041. hba->num_ofld_sess = 0;
  1042. hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
  1043. BNX2FC_MAX_XID);
  1044. if (!hba->cmd_mgr) {
  1045. printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
  1046. goto cmgr_err;
  1047. }
  1048. init_waitqueue_head(&hba->shutdown_wait);
  1049. init_waitqueue_head(&hba->destroy_wait);
  1050. INIT_LIST_HEAD(&hba->vports);
  1051. return hba;
  1052. cmgr_err:
  1053. kfree(hba->tgt_ofld_list);
  1054. tgtofld_err:
  1055. bnx2fc_unbind_pcidev(hba);
  1056. bind_err:
  1057. kfree(hba);
  1058. return NULL;
  1059. }
  1060. struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
  1061. struct net_device *netdev,
  1062. enum fip_state fip_mode)
  1063. {
  1064. struct bnx2fc_interface *interface;
  1065. int rc = 0;
  1066. interface = kzalloc(sizeof(*interface), GFP_KERNEL);
  1067. if (!interface) {
  1068. printk(KERN_ERR PFX "Unable to allocate interface structure\n");
  1069. return NULL;
  1070. }
  1071. dev_hold(netdev);
  1072. kref_init(&interface->kref);
  1073. interface->hba = hba;
  1074. interface->netdev = netdev;
  1075. /* Initialize FIP */
  1076. fcoe_ctlr_init(&interface->ctlr, fip_mode);
  1077. interface->ctlr.send = bnx2fc_fip_send;
  1078. interface->ctlr.update_mac = bnx2fc_update_src_mac;
  1079. interface->ctlr.get_src_addr = bnx2fc_get_src_mac;
  1080. set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
  1081. rc = bnx2fc_netdev_setup(interface);
  1082. if (!rc)
  1083. return interface;
  1084. fcoe_ctlr_destroy(&interface->ctlr);
  1085. dev_put(netdev);
  1086. kfree(interface);
  1087. return NULL;
  1088. }
  1089. /**
  1090. * bnx2fc_if_create - Create FCoE instance on a given interface
  1091. *
  1092. * @interface: FCoE interface to create a local port on
  1093. * @parent: Device pointer to be the parent in sysfs for the SCSI host
  1094. * @npiv: Indicates if the port is vport or not
  1095. *
  1096. * Creates a fc_lport instance and a Scsi_Host instance and configure them.
  1097. *
  1098. * Returns: Allocated fc_lport or an error pointer
  1099. */
  1100. static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
  1101. struct device *parent, int npiv)
  1102. {
  1103. struct fc_lport *lport, *n_port;
  1104. struct fcoe_port *port;
  1105. struct Scsi_Host *shost;
  1106. struct fc_vport *vport = dev_to_vport(parent);
  1107. struct bnx2fc_lport *blport;
  1108. struct bnx2fc_hba *hba;
  1109. int rc = 0;
  1110. blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
  1111. if (!blport) {
  1112. BNX2FC_HBA_DBG(interface->ctlr.lp, "Unable to alloc blport\n");
  1113. return NULL;
  1114. }
  1115. /* Allocate Scsi_Host structure */
  1116. if (!npiv)
  1117. lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
  1118. else
  1119. lport = libfc_vport_create(vport, sizeof(*port));
  1120. if (!lport) {
  1121. printk(KERN_ERR PFX "could not allocate scsi host structure\n");
  1122. goto free_blport;
  1123. }
  1124. shost = lport->host;
  1125. port = lport_priv(lport);
  1126. port->lport = lport;
  1127. port->priv = interface;
  1128. INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
  1129. /* Configure fcoe_port */
  1130. rc = bnx2fc_lport_config(lport);
  1131. if (rc)
  1132. goto lp_config_err;
  1133. if (npiv) {
  1134. printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
  1135. vport->node_name, vport->port_name);
  1136. fc_set_wwnn(lport, vport->node_name);
  1137. fc_set_wwpn(lport, vport->port_name);
  1138. }
  1139. /* Configure netdev and networking properties of the lport */
  1140. rc = bnx2fc_net_config(lport);
  1141. if (rc) {
  1142. printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
  1143. goto lp_config_err;
  1144. }
  1145. rc = bnx2fc_shost_config(lport, parent);
  1146. if (rc) {
  1147. printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
  1148. interface->netdev->name);
  1149. goto lp_config_err;
  1150. }
  1151. /* Initialize the libfc library */
  1152. rc = bnx2fc_libfc_config(lport);
  1153. if (rc) {
  1154. printk(KERN_ERR PFX "Couldnt configure libfc\n");
  1155. goto shost_err;
  1156. }
  1157. fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
  1158. /* Allocate exchange manager */
  1159. if (!npiv)
  1160. rc = bnx2fc_em_config(lport);
  1161. else {
  1162. shost = vport_to_shost(vport);
  1163. n_port = shost_priv(shost);
  1164. rc = fc_exch_mgr_list_clone(n_port, lport);
  1165. }
  1166. if (rc) {
  1167. printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
  1168. goto shost_err;
  1169. }
  1170. bnx2fc_interface_get(interface);
  1171. hba = interface->hba;
  1172. spin_lock_bh(&hba->hba_lock);
  1173. blport->lport = lport;
  1174. list_add_tail(&blport->list, &hba->vports);
  1175. spin_unlock_bh(&hba->hba_lock);
  1176. return lport;
  1177. shost_err:
  1178. scsi_remove_host(shost);
  1179. lp_config_err:
  1180. scsi_host_put(lport->host);
  1181. free_blport:
  1182. kfree(blport);
  1183. return NULL;
  1184. }
  1185. static void bnx2fc_netdev_cleanup(struct bnx2fc_interface *interface)
  1186. {
  1187. /* Dont listen for Ethernet packets anymore */
  1188. __dev_remove_pack(&interface->fcoe_packet_type);
  1189. __dev_remove_pack(&interface->fip_packet_type);
  1190. synchronize_net();
  1191. }
  1192. static void bnx2fc_if_destroy(struct fc_lport *lport, struct bnx2fc_hba *hba)
  1193. {
  1194. struct fcoe_port *port = lport_priv(lport);
  1195. struct bnx2fc_lport *blport, *tmp;
  1196. /* Stop the transmit retry timer */
  1197. del_timer_sync(&port->timer);
  1198. /* Free existing transmit skbs */
  1199. fcoe_clean_pending_queue(lport);
  1200. /* Free queued packets for the receive thread */
  1201. bnx2fc_clean_rx_queue(lport);
  1202. /* Detach from scsi-ml */
  1203. fc_remove_host(lport->host);
  1204. scsi_remove_host(lport->host);
  1205. /*
  1206. * Note that only the physical lport will have the exchange manager.
  1207. * for vports, this function is NOP
  1208. */
  1209. fc_exch_mgr_free(lport);
  1210. /* Free memory used by statistical counters */
  1211. fc_lport_free_stats(lport);
  1212. spin_lock_bh(&hba->hba_lock);
  1213. list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
  1214. if (blport->lport == lport) {
  1215. list_del(&blport->list);
  1216. kfree(blport);
  1217. }
  1218. }
  1219. spin_unlock_bh(&hba->hba_lock);
  1220. /* Release Scsi_Host */
  1221. scsi_host_put(lport->host);
  1222. }
  1223. /**
  1224. * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
  1225. *
  1226. * @buffer: The name of the Ethernet interface to be destroyed
  1227. * @kp: The associated kernel parameter
  1228. *
  1229. * Called from sysfs.
  1230. *
  1231. * Returns: 0 for success
  1232. */
  1233. static int bnx2fc_destroy(struct net_device *netdev)
  1234. {
  1235. struct bnx2fc_interface *interface = NULL;
  1236. struct bnx2fc_hba *hba;
  1237. struct fc_lport *lport;
  1238. int rc = 0;
  1239. rtnl_lock();
  1240. mutex_lock(&bnx2fc_dev_lock);
  1241. interface = bnx2fc_interface_lookup(netdev);
  1242. if (!interface || !interface->ctlr.lp) {
  1243. rc = -ENODEV;
  1244. printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
  1245. goto netdev_err;
  1246. }
  1247. hba = interface->hba;
  1248. bnx2fc_netdev_cleanup(interface);
  1249. lport = interface->ctlr.lp;
  1250. bnx2fc_stop(interface);
  1251. list_del(&interface->list);
  1252. destroy_workqueue(interface->timer_work_queue);
  1253. bnx2fc_interface_put(interface);
  1254. bnx2fc_if_destroy(lport, hba);
  1255. netdev_err:
  1256. mutex_unlock(&bnx2fc_dev_lock);
  1257. rtnl_unlock();
  1258. return rc;
  1259. }
  1260. static void bnx2fc_destroy_work(struct work_struct *work)
  1261. {
  1262. struct fcoe_port *port;
  1263. struct fc_lport *lport;
  1264. struct bnx2fc_interface *interface;
  1265. struct bnx2fc_hba *hba;
  1266. port = container_of(work, struct fcoe_port, destroy_work);
  1267. lport = port->lport;
  1268. interface = port->priv;
  1269. hba = interface->hba;
  1270. BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
  1271. bnx2fc_port_shutdown(lport);
  1272. rtnl_lock();
  1273. mutex_lock(&bnx2fc_dev_lock);
  1274. bnx2fc_if_destroy(lport, hba);
  1275. mutex_unlock(&bnx2fc_dev_lock);
  1276. rtnl_unlock();
  1277. }
  1278. static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
  1279. {
  1280. bnx2fc_free_fw_resc(hba);
  1281. bnx2fc_free_task_ctx(hba);
  1282. }
  1283. /**
  1284. * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
  1285. * pci structure
  1286. *
  1287. * @hba: Adapter instance
  1288. */
  1289. static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
  1290. {
  1291. if (bnx2fc_setup_task_ctx(hba))
  1292. goto mem_err;
  1293. if (bnx2fc_setup_fw_resc(hba))
  1294. goto mem_err;
  1295. return 0;
  1296. mem_err:
  1297. bnx2fc_unbind_adapter_devices(hba);
  1298. return -ENOMEM;
  1299. }
  1300. static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
  1301. {
  1302. struct cnic_dev *cnic;
  1303. if (!hba->cnic) {
  1304. printk(KERN_ERR PFX "cnic is NULL\n");
  1305. return -ENODEV;
  1306. }
  1307. cnic = hba->cnic;
  1308. hba->pcidev = cnic->pcidev;
  1309. if (hba->pcidev)
  1310. pci_dev_get(hba->pcidev);
  1311. return 0;
  1312. }
  1313. static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
  1314. {
  1315. if (hba->pcidev)
  1316. pci_dev_put(hba->pcidev);
  1317. hba->pcidev = NULL;
  1318. }
  1319. /**
  1320. * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
  1321. *
  1322. * @handle: transport handle pointing to adapter struture
  1323. *
  1324. * This function maps adapter structure to pcidev structure and initiates
  1325. * firmware handshake to enable/initialize on-chip FCoE components.
  1326. * This bnx2fc - cnic interface api callback is used after following
  1327. * conditions are met -
  1328. * a) underlying network interface is up (marked by event NETDEV_UP
  1329. * from netdev
  1330. * b) bnx2fc adatper structure is registered.
  1331. */
  1332. static void bnx2fc_ulp_start(void *handle)
  1333. {
  1334. struct bnx2fc_hba *hba = handle;
  1335. struct bnx2fc_interface *interface;
  1336. struct fc_lport *lport;
  1337. mutex_lock(&bnx2fc_dev_lock);
  1338. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
  1339. bnx2fc_fw_init(hba);
  1340. BNX2FC_MISC_DBG("bnx2fc started.\n");
  1341. list_for_each_entry(interface, &if_list, list) {
  1342. if (interface->hba == hba) {
  1343. lport = interface->ctlr.lp;
  1344. /* Kick off Fabric discovery*/
  1345. printk(KERN_ERR PFX "ulp_init: start discovery\n");
  1346. lport->tt.frame_send = bnx2fc_xmit;
  1347. bnx2fc_start_disc(interface);
  1348. }
  1349. }
  1350. mutex_unlock(&bnx2fc_dev_lock);
  1351. }
  1352. static void bnx2fc_port_shutdown(struct fc_lport *lport)
  1353. {
  1354. BNX2FC_MISC_DBG("Entered %s\n", __func__);
  1355. fc_fabric_logoff(lport);
  1356. fc_lport_destroy(lport);
  1357. }
  1358. static void bnx2fc_stop(struct bnx2fc_interface *interface)
  1359. {
  1360. struct fc_lport *lport;
  1361. struct fc_lport *vport;
  1362. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
  1363. return;
  1364. lport = interface->ctlr.lp;
  1365. bnx2fc_port_shutdown(lport);
  1366. mutex_lock(&lport->lp_mutex);
  1367. list_for_each_entry(vport, &lport->vports, list)
  1368. fc_host_port_type(vport->host) =
  1369. FC_PORTTYPE_UNKNOWN;
  1370. mutex_unlock(&lport->lp_mutex);
  1371. fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
  1372. fcoe_ctlr_link_down(&interface->ctlr);
  1373. fcoe_clean_pending_queue(lport);
  1374. }
  1375. static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
  1376. {
  1377. #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
  1378. int rc = -1;
  1379. int i = HZ;
  1380. rc = bnx2fc_bind_adapter_devices(hba);
  1381. if (rc) {
  1382. printk(KERN_ALERT PFX
  1383. "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
  1384. goto err_out;
  1385. }
  1386. rc = bnx2fc_send_fw_fcoe_init_msg(hba);
  1387. if (rc) {
  1388. printk(KERN_ALERT PFX
  1389. "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
  1390. goto err_unbind;
  1391. }
  1392. /*
  1393. * Wait until the adapter init message is complete, and adapter
  1394. * state is UP.
  1395. */
  1396. while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
  1397. msleep(BNX2FC_INIT_POLL_TIME);
  1398. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
  1399. printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
  1400. "Ignoring...\n",
  1401. hba->cnic->netdev->name);
  1402. rc = -1;
  1403. goto err_unbind;
  1404. }
  1405. set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
  1406. return 0;
  1407. err_unbind:
  1408. bnx2fc_unbind_adapter_devices(hba);
  1409. err_out:
  1410. return rc;
  1411. }
  1412. static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
  1413. {
  1414. if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
  1415. if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
  1416. init_timer(&hba->destroy_timer);
  1417. hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
  1418. jiffies;
  1419. hba->destroy_timer.function = bnx2fc_destroy_timer;
  1420. hba->destroy_timer.data = (unsigned long)hba;
  1421. add_timer(&hba->destroy_timer);
  1422. wait_event_interruptible(hba->destroy_wait,
  1423. test_bit(BNX2FC_FLAG_DESTROY_CMPL,
  1424. &hba->flags));
  1425. /* This should never happen */
  1426. if (signal_pending(current))
  1427. flush_signals(current);
  1428. del_timer_sync(&hba->destroy_timer);
  1429. }
  1430. bnx2fc_unbind_adapter_devices(hba);
  1431. }
  1432. }
  1433. /**
  1434. * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
  1435. *
  1436. * @handle: transport handle pointing to adapter structure
  1437. *
  1438. * Driver checks if adapter is already in shutdown mode, if not start
  1439. * the shutdown process.
  1440. */
  1441. static void bnx2fc_ulp_stop(void *handle)
  1442. {
  1443. struct bnx2fc_hba *hba = handle;
  1444. struct bnx2fc_interface *interface;
  1445. printk(KERN_ERR "ULP_STOP\n");
  1446. mutex_lock(&bnx2fc_dev_lock);
  1447. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
  1448. goto exit;
  1449. list_for_each_entry(interface, &if_list, list) {
  1450. if (interface->hba == hba)
  1451. bnx2fc_stop(interface);
  1452. }
  1453. BUG_ON(hba->num_ofld_sess != 0);
  1454. mutex_lock(&hba->hba_mutex);
  1455. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  1456. clear_bit(ADAPTER_STATE_GOING_DOWN,
  1457. &hba->adapter_state);
  1458. clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
  1459. mutex_unlock(&hba->hba_mutex);
  1460. bnx2fc_fw_destroy(hba);
  1461. exit:
  1462. mutex_unlock(&bnx2fc_dev_lock);
  1463. }
  1464. static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
  1465. {
  1466. struct fc_lport *lport;
  1467. int wait_cnt = 0;
  1468. BNX2FC_MISC_DBG("Entered %s\n", __func__);
  1469. /* Kick off FIP/FLOGI */
  1470. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
  1471. printk(KERN_ERR PFX "Init not done yet\n");
  1472. return;
  1473. }
  1474. lport = interface->ctlr.lp;
  1475. BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
  1476. if (!bnx2fc_link_ok(lport)) {
  1477. BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
  1478. fcoe_ctlr_link_up(&interface->ctlr);
  1479. fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
  1480. set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
  1481. }
  1482. /* wait for the FCF to be selected before issuing FLOGI */
  1483. while (!interface->ctlr.sel_fcf) {
  1484. msleep(250);
  1485. /* give up after 3 secs */
  1486. if (++wait_cnt > 12)
  1487. break;
  1488. }
  1489. fc_lport_init(lport);
  1490. fc_fabric_login(lport);
  1491. }
  1492. /**
  1493. * bnx2fc_ulp_init - Initialize an adapter instance
  1494. *
  1495. * @dev : cnic device handle
  1496. * Called from cnic_register_driver() context to initialize all
  1497. * enumerated cnic devices. This routine allocates adapter structure
  1498. * and other device specific resources.
  1499. */
  1500. static void bnx2fc_ulp_init(struct cnic_dev *dev)
  1501. {
  1502. struct bnx2fc_hba *hba;
  1503. int rc = 0;
  1504. BNX2FC_MISC_DBG("Entered %s\n", __func__);
  1505. /* bnx2fc works only when bnx2x is loaded */
  1506. if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
  1507. (dev->max_fcoe_conn == 0)) {
  1508. printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
  1509. " flags: %lx fcoe_conn: %d\n",
  1510. dev->netdev->name, dev->flags, dev->max_fcoe_conn);
  1511. return;
  1512. }
  1513. hba = bnx2fc_hba_create(dev);
  1514. if (!hba) {
  1515. printk(KERN_ERR PFX "hba initialization failed\n");
  1516. return;
  1517. }
  1518. /* Add HBA to the adapter list */
  1519. mutex_lock(&bnx2fc_dev_lock);
  1520. list_add_tail(&hba->list, &adapter_list);
  1521. adapter_count++;
  1522. mutex_unlock(&bnx2fc_dev_lock);
  1523. clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
  1524. rc = dev->register_device(dev, CNIC_ULP_FCOE,
  1525. (void *) hba);
  1526. if (rc)
  1527. printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
  1528. else
  1529. set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
  1530. }
  1531. static int bnx2fc_disable(struct net_device *netdev)
  1532. {
  1533. struct bnx2fc_interface *interface;
  1534. int rc = 0;
  1535. rtnl_lock();
  1536. mutex_lock(&bnx2fc_dev_lock);
  1537. interface = bnx2fc_interface_lookup(netdev);
  1538. if (!interface || !interface->ctlr.lp) {
  1539. rc = -ENODEV;
  1540. printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
  1541. } else {
  1542. fcoe_ctlr_link_down(&interface->ctlr);
  1543. fcoe_clean_pending_queue(interface->ctlr.lp);
  1544. }
  1545. mutex_unlock(&bnx2fc_dev_lock);
  1546. rtnl_unlock();
  1547. return rc;
  1548. }
  1549. static int bnx2fc_enable(struct net_device *netdev)
  1550. {
  1551. struct bnx2fc_interface *interface;
  1552. int rc = 0;
  1553. rtnl_lock();
  1554. mutex_lock(&bnx2fc_dev_lock);
  1555. interface = bnx2fc_interface_lookup(netdev);
  1556. if (!interface || !interface->ctlr.lp) {
  1557. rc = -ENODEV;
  1558. printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
  1559. } else if (!bnx2fc_link_ok(interface->ctlr.lp))
  1560. fcoe_ctlr_link_up(&interface->ctlr);
  1561. mutex_unlock(&bnx2fc_dev_lock);
  1562. rtnl_unlock();
  1563. return rc;
  1564. }
  1565. /**
  1566. * bnx2fc_create - Create bnx2fc FCoE interface
  1567. *
  1568. * @buffer: The name of Ethernet interface to create on
  1569. * @kp: The associated kernel param
  1570. *
  1571. * Called from sysfs.
  1572. *
  1573. * Returns: 0 for success
  1574. */
  1575. static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
  1576. {
  1577. struct bnx2fc_interface *interface;
  1578. struct bnx2fc_hba *hba;
  1579. struct net_device *phys_dev;
  1580. struct fc_lport *lport;
  1581. struct ethtool_drvinfo drvinfo;
  1582. int rc = 0;
  1583. int vlan_id;
  1584. BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
  1585. if (fip_mode != FIP_MODE_FABRIC) {
  1586. printk(KERN_ERR "fip mode not FABRIC\n");
  1587. return -EIO;
  1588. }
  1589. rtnl_lock();
  1590. mutex_lock(&bnx2fc_dev_lock);
  1591. if (!try_module_get(THIS_MODULE)) {
  1592. rc = -EINVAL;
  1593. goto mod_err;
  1594. }
  1595. /* obtain physical netdev */
  1596. if (netdev->priv_flags & IFF_802_1Q_VLAN) {
  1597. phys_dev = vlan_dev_real_dev(netdev);
  1598. vlan_id = vlan_dev_vlan_id(netdev);
  1599. } else {
  1600. printk(KERN_ERR PFX "Not a vlan device\n");
  1601. rc = -EINVAL;
  1602. goto netdev_err;
  1603. }
  1604. /* verify if the physical device is a netxtreme2 device */
  1605. if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
  1606. memset(&drvinfo, 0, sizeof(drvinfo));
  1607. phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
  1608. if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
  1609. printk(KERN_ERR PFX "Not a netxtreme2 device\n");
  1610. rc = -EINVAL;
  1611. goto netdev_err;
  1612. }
  1613. } else {
  1614. printk(KERN_ERR PFX "unable to obtain drv_info\n");
  1615. rc = -EINVAL;
  1616. goto netdev_err;
  1617. }
  1618. /* obtain interface and initialize rest of the structure */
  1619. hba = bnx2fc_hba_lookup(phys_dev);
  1620. if (!hba) {
  1621. rc = -ENODEV;
  1622. printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
  1623. goto netdev_err;
  1624. }
  1625. if (bnx2fc_interface_lookup(netdev)) {
  1626. rc = -EEXIST;
  1627. goto netdev_err;
  1628. }
  1629. interface = bnx2fc_interface_create(hba, netdev, fip_mode);
  1630. if (!interface) {
  1631. printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
  1632. goto ifput_err;
  1633. }
  1634. interface->vlan_id = vlan_id;
  1635. interface->vlan_enabled = 1;
  1636. interface->timer_work_queue =
  1637. create_singlethread_workqueue("bnx2fc_timer_wq");
  1638. if (!interface->timer_work_queue) {
  1639. printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
  1640. rc = -EINVAL;
  1641. goto ifput_err;
  1642. }
  1643. lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
  1644. if (!lport) {
  1645. printk(KERN_ERR PFX "Failed to create interface (%s)\n",
  1646. netdev->name);
  1647. bnx2fc_netdev_cleanup(interface);
  1648. rc = -EINVAL;
  1649. goto if_create_err;
  1650. }
  1651. /* Add interface to if_list */
  1652. list_add_tail(&interface->list, &if_list);
  1653. lport->boot_time = jiffies;
  1654. /* Make this master N_port */
  1655. interface->ctlr.lp = lport;
  1656. BNX2FC_HBA_DBG(lport, "create: START DISC\n");
  1657. bnx2fc_start_disc(interface);
  1658. /*
  1659. * Release from kref_init in bnx2fc_interface_setup, on success
  1660. * lport should be holding a reference taken in bnx2fc_if_create
  1661. */
  1662. bnx2fc_interface_put(interface);
  1663. /* put netdev that was held while calling dev_get_by_name */
  1664. mutex_unlock(&bnx2fc_dev_lock);
  1665. rtnl_unlock();
  1666. return 0;
  1667. if_create_err:
  1668. destroy_workqueue(interface->timer_work_queue);
  1669. ifput_err:
  1670. bnx2fc_interface_put(interface);
  1671. netdev_err:
  1672. module_put(THIS_MODULE);
  1673. mod_err:
  1674. mutex_unlock(&bnx2fc_dev_lock);
  1675. rtnl_unlock();
  1676. return rc;
  1677. }
  1678. /**
  1679. * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
  1680. *
  1681. * @cnic: Pointer to cnic device instance
  1682. *
  1683. **/
  1684. static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
  1685. {
  1686. struct list_head *list;
  1687. struct list_head *temp;
  1688. struct bnx2fc_hba *hba;
  1689. /* Called with bnx2fc_dev_lock held */
  1690. list_for_each_safe(list, temp, &adapter_list) {
  1691. hba = (struct bnx2fc_hba *)list;
  1692. if (hba->cnic == cnic)
  1693. return hba;
  1694. }
  1695. return NULL;
  1696. }
  1697. static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
  1698. *netdev)
  1699. {
  1700. struct bnx2fc_interface *interface;
  1701. /* Called with bnx2fc_dev_lock held */
  1702. list_for_each_entry(interface, &if_list, list) {
  1703. if (interface->netdev == netdev)
  1704. return interface;
  1705. }
  1706. return NULL;
  1707. }
  1708. static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
  1709. *phys_dev)
  1710. {
  1711. struct bnx2fc_hba *hba;
  1712. /* Called with bnx2fc_dev_lock held */
  1713. list_for_each_entry(hba, &adapter_list, list) {
  1714. if (hba->phys_dev == phys_dev)
  1715. return hba;
  1716. }
  1717. printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
  1718. return NULL;
  1719. }
  1720. /**
  1721. * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
  1722. *
  1723. * @dev cnic device handle
  1724. */
  1725. static void bnx2fc_ulp_exit(struct cnic_dev *dev)
  1726. {
  1727. struct bnx2fc_hba *hba;
  1728. struct bnx2fc_interface *interface, *tmp;
  1729. struct fc_lport *lport;
  1730. BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
  1731. if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
  1732. printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
  1733. dev->netdev->name, dev->flags);
  1734. return;
  1735. }
  1736. mutex_lock(&bnx2fc_dev_lock);
  1737. hba = bnx2fc_find_hba_for_cnic(dev);
  1738. if (!hba) {
  1739. printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
  1740. dev);
  1741. mutex_unlock(&bnx2fc_dev_lock);
  1742. return;
  1743. }
  1744. list_del_init(&hba->list);
  1745. adapter_count--;
  1746. list_for_each_entry_safe(interface, tmp, &if_list, list) {
  1747. /* destroy not called yet, move to quiesced list */
  1748. if (interface->hba == hba) {
  1749. bnx2fc_netdev_cleanup(interface);
  1750. bnx2fc_stop(interface);
  1751. list_del(&interface->list);
  1752. lport = interface->ctlr.lp;
  1753. bnx2fc_interface_put(interface);
  1754. bnx2fc_if_destroy(lport, hba);
  1755. }
  1756. }
  1757. mutex_unlock(&bnx2fc_dev_lock);
  1758. bnx2fc_ulp_stop(hba);
  1759. /* unregister cnic device */
  1760. if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
  1761. hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
  1762. bnx2fc_hba_destroy(hba);
  1763. }
  1764. /**
  1765. * bnx2fc_fcoe_reset - Resets the fcoe
  1766. *
  1767. * @shost: shost the reset is from
  1768. *
  1769. * Returns: always 0
  1770. */
  1771. static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
  1772. {
  1773. struct fc_lport *lport = shost_priv(shost);
  1774. fc_lport_reset(lport);
  1775. return 0;
  1776. }
  1777. static bool bnx2fc_match(struct net_device *netdev)
  1778. {
  1779. mutex_lock(&bnx2fc_dev_lock);
  1780. if (netdev->priv_flags & IFF_802_1Q_VLAN) {
  1781. struct net_device *phys_dev = vlan_dev_real_dev(netdev);
  1782. if (bnx2fc_hba_lookup(phys_dev)) {
  1783. mutex_unlock(&bnx2fc_dev_lock);
  1784. return true;
  1785. }
  1786. }
  1787. mutex_unlock(&bnx2fc_dev_lock);
  1788. return false;
  1789. }
  1790. static struct fcoe_transport bnx2fc_transport = {
  1791. .name = {"bnx2fc"},
  1792. .attached = false,
  1793. .list = LIST_HEAD_INIT(bnx2fc_transport.list),
  1794. .match = bnx2fc_match,
  1795. .create = bnx2fc_create,
  1796. .destroy = bnx2fc_destroy,
  1797. .enable = bnx2fc_enable,
  1798. .disable = bnx2fc_disable,
  1799. };
  1800. /**
  1801. * bnx2fc_percpu_thread_create - Create a receive thread for an
  1802. * online CPU
  1803. *
  1804. * @cpu: cpu index for the online cpu
  1805. */
  1806. static void bnx2fc_percpu_thread_create(unsigned int cpu)
  1807. {
  1808. struct bnx2fc_percpu_s *p;
  1809. struct task_struct *thread;
  1810. p = &per_cpu(bnx2fc_percpu, cpu);
  1811. thread = kthread_create(bnx2fc_percpu_io_thread,
  1812. (void *)p,
  1813. "bnx2fc_thread/%d", cpu);
  1814. /* bind thread to the cpu */
  1815. if (likely(!IS_ERR(p->iothread))) {
  1816. kthread_bind(thread, cpu);
  1817. p->iothread = thread;
  1818. wake_up_process(thread);
  1819. }
  1820. }
  1821. static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
  1822. {
  1823. struct bnx2fc_percpu_s *p;
  1824. struct task_struct *thread;
  1825. struct bnx2fc_work *work, *tmp;
  1826. LIST_HEAD(work_list);
  1827. BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
  1828. /* Prevent any new work from being queued for this CPU */
  1829. p = &per_cpu(bnx2fc_percpu, cpu);
  1830. spin_lock_bh(&p->fp_work_lock);
  1831. thread = p->iothread;
  1832. p->iothread = NULL;
  1833. /* Free all work in the list */
  1834. list_for_each_entry_safe(work, tmp, &work_list, list) {
  1835. list_del_init(&work->list);
  1836. bnx2fc_process_cq_compl(work->tgt, work->wqe);
  1837. kfree(work);
  1838. }
  1839. spin_unlock_bh(&p->fp_work_lock);
  1840. if (thread)
  1841. kthread_stop(thread);
  1842. }
  1843. /**
  1844. * bnx2fc_cpu_callback - Handler for CPU hotplug events
  1845. *
  1846. * @nfb: The callback data block
  1847. * @action: The event triggering the callback
  1848. * @hcpu: The index of the CPU that the event is for
  1849. *
  1850. * This creates or destroys per-CPU data for fcoe
  1851. *
  1852. * Returns NOTIFY_OK always.
  1853. */
  1854. static int bnx2fc_cpu_callback(struct notifier_block *nfb,
  1855. unsigned long action, void *hcpu)
  1856. {
  1857. unsigned cpu = (unsigned long)hcpu;
  1858. switch (action) {
  1859. case CPU_ONLINE:
  1860. case CPU_ONLINE_FROZEN:
  1861. printk(PFX "CPU %x online: Create Rx thread\n", cpu);
  1862. bnx2fc_percpu_thread_create(cpu);
  1863. break;
  1864. case CPU_DEAD:
  1865. case CPU_DEAD_FROZEN:
  1866. printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
  1867. bnx2fc_percpu_thread_destroy(cpu);
  1868. break;
  1869. default:
  1870. break;
  1871. }
  1872. return NOTIFY_OK;
  1873. }
  1874. /**
  1875. * bnx2fc_mod_init - module init entry point
  1876. *
  1877. * Initialize driver wide global data structures, and register
  1878. * with cnic module
  1879. **/
  1880. static int __init bnx2fc_mod_init(void)
  1881. {
  1882. struct fcoe_percpu_s *bg;
  1883. struct task_struct *l2_thread;
  1884. int rc = 0;
  1885. unsigned int cpu = 0;
  1886. struct bnx2fc_percpu_s *p;
  1887. printk(KERN_INFO PFX "%s", version);
  1888. /* register as a fcoe transport */
  1889. rc = fcoe_transport_attach(&bnx2fc_transport);
  1890. if (rc) {
  1891. printk(KERN_ERR "failed to register an fcoe transport, check "
  1892. "if libfcoe is loaded\n");
  1893. goto out;
  1894. }
  1895. INIT_LIST_HEAD(&adapter_list);
  1896. INIT_LIST_HEAD(&if_list);
  1897. mutex_init(&bnx2fc_dev_lock);
  1898. adapter_count = 0;
  1899. /* Attach FC transport template */
  1900. rc = bnx2fc_attach_transport();
  1901. if (rc)
  1902. goto detach_ft;
  1903. bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
  1904. if (!bnx2fc_wq) {
  1905. rc = -ENOMEM;
  1906. goto release_bt;
  1907. }
  1908. bg = &bnx2fc_global;
  1909. skb_queue_head_init(&bg->fcoe_rx_list);
  1910. l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
  1911. (void *)bg,
  1912. "bnx2fc_l2_thread");
  1913. if (IS_ERR(l2_thread)) {
  1914. rc = PTR_ERR(l2_thread);
  1915. goto free_wq;
  1916. }
  1917. wake_up_process(l2_thread);
  1918. spin_lock_bh(&bg->fcoe_rx_list.lock);
  1919. bg->thread = l2_thread;
  1920. spin_unlock_bh(&bg->fcoe_rx_list.lock);
  1921. for_each_possible_cpu(cpu) {
  1922. p = &per_cpu(bnx2fc_percpu, cpu);
  1923. INIT_LIST_HEAD(&p->work_list);
  1924. spin_lock_init(&p->fp_work_lock);
  1925. }
  1926. for_each_online_cpu(cpu) {
  1927. bnx2fc_percpu_thread_create(cpu);
  1928. }
  1929. /* Initialize per CPU interrupt thread */
  1930. register_hotcpu_notifier(&bnx2fc_cpu_notifier);
  1931. cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
  1932. return 0;
  1933. free_wq:
  1934. destroy_workqueue(bnx2fc_wq);
  1935. release_bt:
  1936. bnx2fc_release_transport();
  1937. detach_ft:
  1938. fcoe_transport_detach(&bnx2fc_transport);
  1939. out:
  1940. return rc;
  1941. }
  1942. static void __exit bnx2fc_mod_exit(void)
  1943. {
  1944. LIST_HEAD(to_be_deleted);
  1945. struct bnx2fc_hba *hba, *next;
  1946. struct fcoe_percpu_s *bg;
  1947. struct task_struct *l2_thread;
  1948. struct sk_buff *skb;
  1949. unsigned int cpu = 0;
  1950. /*
  1951. * NOTE: Since cnic calls register_driver routine rtnl_lock,
  1952. * it will have higher precedence than bnx2fc_dev_lock.
  1953. * unregister_device() cannot be called with bnx2fc_dev_lock
  1954. * held.
  1955. */
  1956. mutex_lock(&bnx2fc_dev_lock);
  1957. list_splice(&adapter_list, &to_be_deleted);
  1958. INIT_LIST_HEAD(&adapter_list);
  1959. adapter_count = 0;
  1960. mutex_unlock(&bnx2fc_dev_lock);
  1961. /* Unregister with cnic */
  1962. list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
  1963. list_del_init(&hba->list);
  1964. printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
  1965. hba);
  1966. bnx2fc_ulp_stop(hba);
  1967. /* unregister cnic device */
  1968. if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
  1969. &hba->reg_with_cnic))
  1970. hba->cnic->unregister_device(hba->cnic,
  1971. CNIC_ULP_FCOE);
  1972. bnx2fc_hba_destroy(hba);
  1973. }
  1974. cnic_unregister_driver(CNIC_ULP_FCOE);
  1975. /* Destroy global thread */
  1976. bg = &bnx2fc_global;
  1977. spin_lock_bh(&bg->fcoe_rx_list.lock);
  1978. l2_thread = bg->thread;
  1979. bg->thread = NULL;
  1980. while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
  1981. kfree_skb(skb);
  1982. spin_unlock_bh(&bg->fcoe_rx_list.lock);
  1983. if (l2_thread)
  1984. kthread_stop(l2_thread);
  1985. unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
  1986. /* Destroy per cpu threads */
  1987. for_each_online_cpu(cpu) {
  1988. bnx2fc_percpu_thread_destroy(cpu);
  1989. }
  1990. destroy_workqueue(bnx2fc_wq);
  1991. /*
  1992. * detach from scsi transport
  1993. * must happen after all destroys are done
  1994. */
  1995. bnx2fc_release_transport();
  1996. /* detach from fcoe transport */
  1997. fcoe_transport_detach(&bnx2fc_transport);
  1998. }
  1999. module_init(bnx2fc_mod_init);
  2000. module_exit(bnx2fc_mod_exit);
  2001. static struct fc_function_template bnx2fc_transport_function = {
  2002. .show_host_node_name = 1,
  2003. .show_host_port_name = 1,
  2004. .show_host_supported_classes = 1,
  2005. .show_host_supported_fc4s = 1,
  2006. .show_host_active_fc4s = 1,
  2007. .show_host_maxframe_size = 1,
  2008. .show_host_port_id = 1,
  2009. .show_host_supported_speeds = 1,
  2010. .get_host_speed = fc_get_host_speed,
  2011. .show_host_speed = 1,
  2012. .show_host_port_type = 1,
  2013. .get_host_port_state = fc_get_host_port_state,
  2014. .show_host_port_state = 1,
  2015. .show_host_symbolic_name = 1,
  2016. .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
  2017. sizeof(struct bnx2fc_rport)),
  2018. .show_rport_maxframe_size = 1,
  2019. .show_rport_supported_classes = 1,
  2020. .show_host_fabric_name = 1,
  2021. .show_starget_node_name = 1,
  2022. .show_starget_port_name = 1,
  2023. .show_starget_port_id = 1,
  2024. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  2025. .show_rport_dev_loss_tmo = 1,
  2026. .get_fc_host_stats = bnx2fc_get_host_stats,
  2027. .issue_fc_host_lip = bnx2fc_fcoe_reset,
  2028. .terminate_rport_io = fc_rport_terminate_io,
  2029. .vport_create = bnx2fc_vport_create,
  2030. .vport_delete = bnx2fc_vport_destroy,
  2031. .vport_disable = bnx2fc_vport_disable,
  2032. };
  2033. static struct fc_function_template bnx2fc_vport_xport_function = {
  2034. .show_host_node_name = 1,
  2035. .show_host_port_name = 1,
  2036. .show_host_supported_classes = 1,
  2037. .show_host_supported_fc4s = 1,
  2038. .show_host_active_fc4s = 1,
  2039. .show_host_maxframe_size = 1,
  2040. .show_host_port_id = 1,
  2041. .show_host_supported_speeds = 1,
  2042. .get_host_speed = fc_get_host_speed,
  2043. .show_host_speed = 1,
  2044. .show_host_port_type = 1,
  2045. .get_host_port_state = fc_get_host_port_state,
  2046. .show_host_port_state = 1,
  2047. .show_host_symbolic_name = 1,
  2048. .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
  2049. sizeof(struct bnx2fc_rport)),
  2050. .show_rport_maxframe_size = 1,
  2051. .show_rport_supported_classes = 1,
  2052. .show_host_fabric_name = 1,
  2053. .show_starget_node_name = 1,
  2054. .show_starget_port_name = 1,
  2055. .show_starget_port_id = 1,
  2056. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  2057. .show_rport_dev_loss_tmo = 1,
  2058. .get_fc_host_stats = fc_get_host_stats,
  2059. .issue_fc_host_lip = bnx2fc_fcoe_reset,
  2060. .terminate_rport_io = fc_rport_terminate_io,
  2061. };
  2062. /**
  2063. * scsi_host_template structure used while registering with SCSI-ml
  2064. */
  2065. static struct scsi_host_template bnx2fc_shost_template = {
  2066. .module = THIS_MODULE,
  2067. .name = "Broadcom Offload FCoE Initiator",
  2068. .queuecommand = bnx2fc_queuecommand,
  2069. .eh_abort_handler = bnx2fc_eh_abort, /* abts */
  2070. .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
  2071. .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
  2072. .eh_host_reset_handler = fc_eh_host_reset,
  2073. .slave_alloc = fc_slave_alloc,
  2074. .change_queue_depth = fc_change_queue_depth,
  2075. .change_queue_type = fc_change_queue_type,
  2076. .this_id = -1,
  2077. .cmd_per_lun = 3,
  2078. .can_queue = BNX2FC_CAN_QUEUE,
  2079. .use_clustering = ENABLE_CLUSTERING,
  2080. .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
  2081. .max_sectors = 512,
  2082. };
  2083. static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
  2084. .frame_send = bnx2fc_xmit,
  2085. .elsct_send = bnx2fc_elsct_send,
  2086. .fcp_abort_io = bnx2fc_abort_io,
  2087. .fcp_cleanup = bnx2fc_cleanup,
  2088. .rport_event_callback = bnx2fc_rport_event_handler,
  2089. };
  2090. /**
  2091. * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
  2092. * structure carrying callback function pointers
  2093. */
  2094. static struct cnic_ulp_ops bnx2fc_cnic_cb = {
  2095. .owner = THIS_MODULE,
  2096. .cnic_init = bnx2fc_ulp_init,
  2097. .cnic_exit = bnx2fc_ulp_exit,
  2098. .cnic_start = bnx2fc_ulp_start,
  2099. .cnic_stop = bnx2fc_ulp_stop,
  2100. .indicate_kcqes = bnx2fc_indicate_kcqe,
  2101. .indicate_netevent = bnx2fc_indicate_netevent,
  2102. };