bnx2fc_fcoe.c 72 KB

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