bnx2fc_fcoe.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901
  1. /* bnx2fc_fcoe.c: QLogic 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-2015 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 "October 15, 2015"
  24. static char version[] =
  25. "QLogic 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 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. mutex_lock(&hba->hba_stats_mutex);
  557. bnx2fc_stats = fc_get_host_stats(shost);
  558. init_completion(&hba->stat_req_done);
  559. if (bnx2fc_send_stat_req(hba))
  560. goto unlock_stats_mutex;
  561. rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
  562. if (!rc) {
  563. BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
  564. goto unlock_stats_mutex;
  565. }
  566. BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
  567. bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
  568. BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
  569. bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
  570. BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
  571. bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
  572. BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
  573. bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
  574. BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
  575. bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
  576. bnx2fc_stats->dumped_frames = 0;
  577. bnx2fc_stats->lip_count = 0;
  578. bnx2fc_stats->nos_count = 0;
  579. bnx2fc_stats->loss_of_sync_count = 0;
  580. bnx2fc_stats->loss_of_signal_count = 0;
  581. bnx2fc_stats->prim_seq_protocol_err_count = 0;
  582. memcpy(&hba->prev_stats, hba->stats_buffer,
  583. sizeof(struct fcoe_statistics_params));
  584. unlock_stats_mutex:
  585. mutex_unlock(&hba->hba_stats_mutex);
  586. return bnx2fc_stats;
  587. }
  588. static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
  589. {
  590. struct fcoe_port *port = lport_priv(lport);
  591. struct bnx2fc_interface *interface = port->priv;
  592. struct bnx2fc_hba *hba = interface->hba;
  593. struct Scsi_Host *shost = lport->host;
  594. int rc = 0;
  595. shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
  596. shost->max_lun = BNX2FC_MAX_LUN;
  597. shost->max_id = BNX2FC_MAX_FCP_TGT;
  598. shost->max_channel = 0;
  599. if (lport->vport)
  600. shost->transportt = bnx2fc_vport_xport_template;
  601. else
  602. shost->transportt = bnx2fc_transport_template;
  603. /* Add the new host to SCSI-ml */
  604. rc = scsi_add_host(lport->host, dev);
  605. if (rc) {
  606. printk(KERN_ERR PFX "Error on scsi_add_host\n");
  607. return rc;
  608. }
  609. if (!lport->vport)
  610. fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
  611. snprintf(fc_host_symbolic_name(lport->host), 256,
  612. "%s (QLogic %s) v%s over %s",
  613. BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
  614. interface->netdev->name);
  615. return 0;
  616. }
  617. static int bnx2fc_link_ok(struct fc_lport *lport)
  618. {
  619. struct fcoe_port *port = lport_priv(lport);
  620. struct bnx2fc_interface *interface = port->priv;
  621. struct bnx2fc_hba *hba = interface->hba;
  622. struct net_device *dev = hba->phys_dev;
  623. int rc = 0;
  624. if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
  625. clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  626. else {
  627. set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  628. rc = -1;
  629. }
  630. return rc;
  631. }
  632. /**
  633. * bnx2fc_get_link_state - get network link state
  634. *
  635. * @hba: adapter instance pointer
  636. *
  637. * updates adapter structure flag based on netdev state
  638. */
  639. void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
  640. {
  641. if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
  642. set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  643. else
  644. clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  645. }
  646. static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
  647. {
  648. struct bnx2fc_hba *hba;
  649. struct bnx2fc_interface *interface;
  650. struct fcoe_ctlr *ctlr;
  651. struct fcoe_port *port;
  652. u64 wwnn, wwpn;
  653. port = lport_priv(lport);
  654. interface = port->priv;
  655. ctlr = bnx2fc_to_ctlr(interface);
  656. hba = interface->hba;
  657. /* require support for get_pauseparam ethtool op. */
  658. if (!hba->phys_dev->ethtool_ops ||
  659. !hba->phys_dev->ethtool_ops->get_pauseparam)
  660. return -EOPNOTSUPP;
  661. if (fc_set_mfs(lport, BNX2FC_MFS))
  662. return -EINVAL;
  663. skb_queue_head_init(&port->fcoe_pending_queue);
  664. port->fcoe_pending_queue_active = 0;
  665. setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
  666. fcoe_link_speed_update(lport);
  667. if (!lport->vport) {
  668. if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
  669. wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
  670. 1, 0);
  671. BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
  672. fc_set_wwnn(lport, wwnn);
  673. if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
  674. wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
  675. 2, 0);
  676. BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
  677. fc_set_wwpn(lport, wwpn);
  678. }
  679. return 0;
  680. }
  681. static void bnx2fc_destroy_timer(unsigned long data)
  682. {
  683. struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
  684. printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
  685. "Destroy compl not received!!\n");
  686. set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
  687. wake_up_interruptible(&hba->destroy_wait);
  688. }
  689. /**
  690. * bnx2fc_indicate_netevent - Generic netdev event handler
  691. *
  692. * @context: adapter structure pointer
  693. * @event: event type
  694. * @vlan_id: vlan id - associated vlan id with this event
  695. *
  696. * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
  697. * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
  698. */
  699. static void bnx2fc_indicate_netevent(void *context, unsigned long event,
  700. u16 vlan_id)
  701. {
  702. struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
  703. struct fcoe_ctlr_device *cdev;
  704. struct fc_lport *lport;
  705. struct fc_lport *vport;
  706. struct bnx2fc_interface *interface, *tmp;
  707. struct fcoe_ctlr *ctlr;
  708. int wait_for_upload = 0;
  709. u32 link_possible = 1;
  710. if (vlan_id != 0 && event != NETDEV_UNREGISTER)
  711. return;
  712. switch (event) {
  713. case NETDEV_UP:
  714. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
  715. printk(KERN_ERR "indicate_netevent: "\
  716. "hba is not UP!!\n");
  717. break;
  718. case NETDEV_DOWN:
  719. clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  720. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  721. link_possible = 0;
  722. break;
  723. case NETDEV_GOING_DOWN:
  724. set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  725. link_possible = 0;
  726. break;
  727. case NETDEV_CHANGE:
  728. break;
  729. case NETDEV_UNREGISTER:
  730. if (!vlan_id)
  731. return;
  732. mutex_lock(&bnx2fc_dev_lock);
  733. list_for_each_entry_safe(interface, tmp, &if_list, list) {
  734. if (interface->hba == hba &&
  735. interface->vlan_id == (vlan_id & VLAN_VID_MASK))
  736. __bnx2fc_destroy(interface);
  737. }
  738. mutex_unlock(&bnx2fc_dev_lock);
  739. /* Ensure ALL destroy work has been completed before return */
  740. flush_workqueue(bnx2fc_wq);
  741. return;
  742. default:
  743. return;
  744. }
  745. mutex_lock(&bnx2fc_dev_lock);
  746. list_for_each_entry(interface, &if_list, list) {
  747. if (interface->hba != hba)
  748. continue;
  749. ctlr = bnx2fc_to_ctlr(interface);
  750. lport = ctlr->lp;
  751. BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
  752. interface->netdev->name, event);
  753. fcoe_link_speed_update(lport);
  754. cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
  755. if (link_possible && !bnx2fc_link_ok(lport)) {
  756. switch (cdev->enabled) {
  757. case FCOE_CTLR_DISABLED:
  758. pr_info("Link up while interface is disabled.\n");
  759. break;
  760. case FCOE_CTLR_ENABLED:
  761. case FCOE_CTLR_UNUSED:
  762. /* Reset max recv frame size to default */
  763. fc_set_mfs(lport, BNX2FC_MFS);
  764. /*
  765. * ctlr link up will only be handled during
  766. * enable to avoid sending discovery
  767. * solicitation on a stale vlan
  768. */
  769. if (interface->enabled)
  770. fcoe_ctlr_link_up(ctlr);
  771. };
  772. } else if (fcoe_ctlr_link_down(ctlr)) {
  773. switch (cdev->enabled) {
  774. case FCOE_CTLR_DISABLED:
  775. pr_info("Link down while interface is disabled.\n");
  776. break;
  777. case FCOE_CTLR_ENABLED:
  778. case FCOE_CTLR_UNUSED:
  779. mutex_lock(&lport->lp_mutex);
  780. list_for_each_entry(vport, &lport->vports, list)
  781. fc_host_port_type(vport->host) =
  782. FC_PORTTYPE_UNKNOWN;
  783. mutex_unlock(&lport->lp_mutex);
  784. fc_host_port_type(lport->host) =
  785. FC_PORTTYPE_UNKNOWN;
  786. per_cpu_ptr(lport->stats,
  787. get_cpu())->LinkFailureCount++;
  788. put_cpu();
  789. fcoe_clean_pending_queue(lport);
  790. wait_for_upload = 1;
  791. };
  792. }
  793. }
  794. mutex_unlock(&bnx2fc_dev_lock);
  795. if (wait_for_upload) {
  796. clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
  797. init_waitqueue_head(&hba->shutdown_wait);
  798. BNX2FC_MISC_DBG("indicate_netevent "
  799. "num_ofld_sess = %d\n",
  800. hba->num_ofld_sess);
  801. hba->wait_for_link_down = 1;
  802. wait_event_interruptible(hba->shutdown_wait,
  803. (hba->num_ofld_sess == 0));
  804. BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
  805. hba->num_ofld_sess);
  806. hba->wait_for_link_down = 0;
  807. if (signal_pending(current))
  808. flush_signals(current);
  809. }
  810. }
  811. static int bnx2fc_libfc_config(struct fc_lport *lport)
  812. {
  813. /* Set the function pointers set by bnx2fc driver */
  814. memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
  815. sizeof(struct libfc_function_template));
  816. fc_elsct_init(lport);
  817. fc_exch_init(lport);
  818. fc_rport_init(lport);
  819. fc_disc_init(lport);
  820. fc_disc_config(lport, lport);
  821. return 0;
  822. }
  823. static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
  824. {
  825. int fcoe_min_xid, fcoe_max_xid;
  826. fcoe_min_xid = hba->max_xid + 1;
  827. if (nr_cpu_ids <= 2)
  828. fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
  829. else
  830. fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
  831. if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
  832. fcoe_max_xid, NULL)) {
  833. printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
  834. return -ENOMEM;
  835. }
  836. return 0;
  837. }
  838. static int bnx2fc_lport_config(struct fc_lport *lport)
  839. {
  840. lport->link_up = 0;
  841. lport->qfull = 0;
  842. lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
  843. lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
  844. lport->e_d_tov = 2 * 1000;
  845. lport->r_a_tov = 10 * 1000;
  846. lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
  847. FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
  848. lport->does_npiv = 1;
  849. memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
  850. lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
  851. /* alloc stats structure */
  852. if (fc_lport_init_stats(lport))
  853. return -ENOMEM;
  854. /* Finish fc_lport configuration */
  855. fc_lport_config(lport);
  856. return 0;
  857. }
  858. /**
  859. * bnx2fc_fip_recv - handle a received FIP frame.
  860. *
  861. * @skb: the received skb
  862. * @dev: associated &net_device
  863. * @ptype: the &packet_type structure which was used to register this handler.
  864. * @orig_dev: original receive &net_device, in case @ dev is a bond.
  865. *
  866. * Returns: 0 for success
  867. */
  868. static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
  869. struct packet_type *ptype,
  870. struct net_device *orig_dev)
  871. {
  872. struct bnx2fc_interface *interface;
  873. struct fcoe_ctlr *ctlr;
  874. interface = container_of(ptype, struct bnx2fc_interface,
  875. fip_packet_type);
  876. ctlr = bnx2fc_to_ctlr(interface);
  877. fcoe_ctlr_recv(ctlr, skb);
  878. return 0;
  879. }
  880. /**
  881. * bnx2fc_update_src_mac - Update Ethernet MAC filters.
  882. *
  883. * @fip: FCoE controller.
  884. * @old: Unicast MAC address to delete if the MAC is non-zero.
  885. * @new: Unicast MAC address to add.
  886. *
  887. * Remove any previously-set unicast MAC filter.
  888. * Add secondary FCoE MAC address filter for our OUI.
  889. */
  890. static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
  891. {
  892. struct fcoe_port *port = lport_priv(lport);
  893. memcpy(port->data_src_addr, addr, ETH_ALEN);
  894. }
  895. /**
  896. * bnx2fc_get_src_mac - return the ethernet source address for an lport
  897. *
  898. * @lport: libfc port
  899. */
  900. static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
  901. {
  902. struct fcoe_port *port;
  903. port = (struct fcoe_port *)lport_priv(lport);
  904. return port->data_src_addr;
  905. }
  906. /**
  907. * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
  908. *
  909. * @fip: FCoE controller.
  910. * @skb: FIP Packet.
  911. */
  912. static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
  913. {
  914. skb->dev = bnx2fc_from_ctlr(fip)->netdev;
  915. dev_queue_xmit(skb);
  916. }
  917. static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
  918. {
  919. struct Scsi_Host *shost = vport_to_shost(vport);
  920. struct fc_lport *n_port = shost_priv(shost);
  921. struct fcoe_port *port = lport_priv(n_port);
  922. struct bnx2fc_interface *interface = port->priv;
  923. struct net_device *netdev = interface->netdev;
  924. struct fc_lport *vn_port;
  925. int rc;
  926. char buf[32];
  927. rc = fcoe_validate_vport_create(vport);
  928. if (rc) {
  929. fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
  930. printk(KERN_ERR PFX "Failed to create vport, "
  931. "WWPN (0x%s) already exists\n",
  932. buf);
  933. return rc;
  934. }
  935. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
  936. printk(KERN_ERR PFX "vn ports cannot be created on"
  937. "this interface\n");
  938. return -EIO;
  939. }
  940. rtnl_lock();
  941. mutex_lock(&bnx2fc_dev_lock);
  942. vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
  943. mutex_unlock(&bnx2fc_dev_lock);
  944. rtnl_unlock();
  945. if (!vn_port) {
  946. printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
  947. netdev->name);
  948. return -EIO;
  949. }
  950. if (disabled) {
  951. fc_vport_set_state(vport, FC_VPORT_DISABLED);
  952. } else {
  953. vn_port->boot_time = jiffies;
  954. fc_lport_init(vn_port);
  955. fc_fabric_login(vn_port);
  956. fc_vport_setlink(vn_port);
  957. }
  958. return 0;
  959. }
  960. static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
  961. {
  962. struct bnx2fc_lport *blport, *tmp;
  963. spin_lock_bh(&hba->hba_lock);
  964. list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
  965. if (blport->lport == lport) {
  966. list_del(&blport->list);
  967. kfree(blport);
  968. }
  969. }
  970. spin_unlock_bh(&hba->hba_lock);
  971. }
  972. static int bnx2fc_vport_destroy(struct fc_vport *vport)
  973. {
  974. struct Scsi_Host *shost = vport_to_shost(vport);
  975. struct fc_lport *n_port = shost_priv(shost);
  976. struct fc_lport *vn_port = vport->dd_data;
  977. struct fcoe_port *port = lport_priv(vn_port);
  978. struct bnx2fc_interface *interface = port->priv;
  979. struct fc_lport *v_port;
  980. bool found = false;
  981. mutex_lock(&n_port->lp_mutex);
  982. list_for_each_entry(v_port, &n_port->vports, list)
  983. if (v_port->vport == vport) {
  984. found = true;
  985. break;
  986. }
  987. if (!found) {
  988. mutex_unlock(&n_port->lp_mutex);
  989. return -ENOENT;
  990. }
  991. list_del(&vn_port->list);
  992. mutex_unlock(&n_port->lp_mutex);
  993. bnx2fc_free_vport(interface->hba, port->lport);
  994. bnx2fc_port_shutdown(port->lport);
  995. bnx2fc_interface_put(interface);
  996. queue_work(bnx2fc_wq, &port->destroy_work);
  997. return 0;
  998. }
  999. static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
  1000. {
  1001. struct fc_lport *lport = vport->dd_data;
  1002. if (disable) {
  1003. fc_vport_set_state(vport, FC_VPORT_DISABLED);
  1004. fc_fabric_logoff(lport);
  1005. } else {
  1006. lport->boot_time = jiffies;
  1007. fc_fabric_login(lport);
  1008. fc_vport_setlink(lport);
  1009. }
  1010. return 0;
  1011. }
  1012. static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
  1013. {
  1014. struct net_device *netdev = interface->netdev;
  1015. struct net_device *physdev = interface->hba->phys_dev;
  1016. struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
  1017. struct netdev_hw_addr *ha;
  1018. int sel_san_mac = 0;
  1019. /* setup Source MAC Address */
  1020. rcu_read_lock();
  1021. for_each_dev_addr(physdev, ha) {
  1022. BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
  1023. ha->type);
  1024. printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
  1025. ha->addr[1], ha->addr[2], ha->addr[3],
  1026. ha->addr[4], ha->addr[5]);
  1027. if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
  1028. (is_valid_ether_addr(ha->addr))) {
  1029. memcpy(ctlr->ctl_src_addr, ha->addr,
  1030. ETH_ALEN);
  1031. sel_san_mac = 1;
  1032. BNX2FC_MISC_DBG("Found SAN MAC\n");
  1033. }
  1034. }
  1035. rcu_read_unlock();
  1036. if (!sel_san_mac)
  1037. return -ENODEV;
  1038. interface->fip_packet_type.func = bnx2fc_fip_recv;
  1039. interface->fip_packet_type.type = htons(ETH_P_FIP);
  1040. interface->fip_packet_type.dev = netdev;
  1041. dev_add_pack(&interface->fip_packet_type);
  1042. interface->fcoe_packet_type.func = bnx2fc_rcv;
  1043. interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
  1044. interface->fcoe_packet_type.dev = netdev;
  1045. dev_add_pack(&interface->fcoe_packet_type);
  1046. return 0;
  1047. }
  1048. static int bnx2fc_attach_transport(void)
  1049. {
  1050. bnx2fc_transport_template =
  1051. fc_attach_transport(&bnx2fc_transport_function);
  1052. if (bnx2fc_transport_template == NULL) {
  1053. printk(KERN_ERR PFX "Failed to attach FC transport\n");
  1054. return -ENODEV;
  1055. }
  1056. bnx2fc_vport_xport_template =
  1057. fc_attach_transport(&bnx2fc_vport_xport_function);
  1058. if (bnx2fc_vport_xport_template == NULL) {
  1059. printk(KERN_ERR PFX
  1060. "Failed to attach FC transport for vport\n");
  1061. fc_release_transport(bnx2fc_transport_template);
  1062. bnx2fc_transport_template = NULL;
  1063. return -ENODEV;
  1064. }
  1065. return 0;
  1066. }
  1067. static void bnx2fc_release_transport(void)
  1068. {
  1069. fc_release_transport(bnx2fc_transport_template);
  1070. fc_release_transport(bnx2fc_vport_xport_template);
  1071. bnx2fc_transport_template = NULL;
  1072. bnx2fc_vport_xport_template = NULL;
  1073. }
  1074. static void bnx2fc_interface_release(struct kref *kref)
  1075. {
  1076. struct fcoe_ctlr_device *ctlr_dev;
  1077. struct bnx2fc_interface *interface;
  1078. struct fcoe_ctlr *ctlr;
  1079. struct net_device *netdev;
  1080. interface = container_of(kref, struct bnx2fc_interface, kref);
  1081. BNX2FC_MISC_DBG("Interface is being released\n");
  1082. ctlr = bnx2fc_to_ctlr(interface);
  1083. ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
  1084. netdev = interface->netdev;
  1085. /* tear-down FIP controller */
  1086. if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
  1087. fcoe_ctlr_destroy(ctlr);
  1088. fcoe_ctlr_device_delete(ctlr_dev);
  1089. dev_put(netdev);
  1090. module_put(THIS_MODULE);
  1091. }
  1092. static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
  1093. {
  1094. kref_get(&interface->kref);
  1095. }
  1096. static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
  1097. {
  1098. kref_put(&interface->kref, bnx2fc_interface_release);
  1099. }
  1100. static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
  1101. {
  1102. /* Free the command manager */
  1103. if (hba->cmd_mgr) {
  1104. bnx2fc_cmd_mgr_free(hba->cmd_mgr);
  1105. hba->cmd_mgr = NULL;
  1106. }
  1107. kfree(hba->tgt_ofld_list);
  1108. bnx2fc_unbind_pcidev(hba);
  1109. kfree(hba);
  1110. }
  1111. /**
  1112. * bnx2fc_hba_create - create a new bnx2fc hba
  1113. *
  1114. * @cnic: pointer to cnic device
  1115. *
  1116. * Creates a new FCoE hba on the given device.
  1117. *
  1118. */
  1119. static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
  1120. {
  1121. struct bnx2fc_hba *hba;
  1122. struct fcoe_capabilities *fcoe_cap;
  1123. int rc;
  1124. hba = kzalloc(sizeof(*hba), GFP_KERNEL);
  1125. if (!hba) {
  1126. printk(KERN_ERR PFX "Unable to allocate hba structure\n");
  1127. return NULL;
  1128. }
  1129. spin_lock_init(&hba->hba_lock);
  1130. mutex_init(&hba->hba_mutex);
  1131. mutex_init(&hba->hba_stats_mutex);
  1132. hba->cnic = cnic;
  1133. hba->max_tasks = cnic->max_fcoe_exchanges;
  1134. hba->elstm_xids = (hba->max_tasks / 2);
  1135. hba->max_outstanding_cmds = hba->elstm_xids;
  1136. hba->max_xid = (hba->max_tasks - 1);
  1137. rc = bnx2fc_bind_pcidev(hba);
  1138. if (rc) {
  1139. printk(KERN_ERR PFX "create_adapter: bind error\n");
  1140. goto bind_err;
  1141. }
  1142. hba->phys_dev = cnic->netdev;
  1143. hba->next_conn_id = 0;
  1144. hba->tgt_ofld_list =
  1145. kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
  1146. GFP_KERNEL);
  1147. if (!hba->tgt_ofld_list) {
  1148. printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
  1149. goto tgtofld_err;
  1150. }
  1151. hba->num_ofld_sess = 0;
  1152. hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
  1153. if (!hba->cmd_mgr) {
  1154. printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
  1155. goto cmgr_err;
  1156. }
  1157. fcoe_cap = &hba->fcoe_cap;
  1158. fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
  1159. FCOE_IOS_PER_CONNECTION_SHIFT;
  1160. fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
  1161. FCOE_LOGINS_PER_PORT_SHIFT;
  1162. fcoe_cap->capability2 = hba->max_outstanding_cmds <<
  1163. FCOE_NUMBER_OF_EXCHANGES_SHIFT;
  1164. fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
  1165. FCOE_NPIV_WWN_PER_PORT_SHIFT;
  1166. fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
  1167. FCOE_TARGETS_SUPPORTED_SHIFT;
  1168. fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
  1169. FCOE_OUTSTANDING_COMMANDS_SHIFT;
  1170. fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
  1171. init_waitqueue_head(&hba->shutdown_wait);
  1172. init_waitqueue_head(&hba->destroy_wait);
  1173. INIT_LIST_HEAD(&hba->vports);
  1174. return hba;
  1175. cmgr_err:
  1176. kfree(hba->tgt_ofld_list);
  1177. tgtofld_err:
  1178. bnx2fc_unbind_pcidev(hba);
  1179. bind_err:
  1180. kfree(hba);
  1181. return NULL;
  1182. }
  1183. struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
  1184. struct net_device *netdev,
  1185. enum fip_state fip_mode)
  1186. {
  1187. struct fcoe_ctlr_device *ctlr_dev;
  1188. struct bnx2fc_interface *interface;
  1189. struct fcoe_ctlr *ctlr;
  1190. int size;
  1191. int rc = 0;
  1192. size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
  1193. ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
  1194. size);
  1195. if (!ctlr_dev) {
  1196. printk(KERN_ERR PFX "Unable to allocate interface structure\n");
  1197. return NULL;
  1198. }
  1199. ctlr = fcoe_ctlr_device_priv(ctlr_dev);
  1200. ctlr->cdev = ctlr_dev;
  1201. interface = fcoe_ctlr_priv(ctlr);
  1202. dev_hold(netdev);
  1203. kref_init(&interface->kref);
  1204. interface->hba = hba;
  1205. interface->netdev = netdev;
  1206. /* Initialize FIP */
  1207. fcoe_ctlr_init(ctlr, fip_mode);
  1208. ctlr->send = bnx2fc_fip_send;
  1209. ctlr->update_mac = bnx2fc_update_src_mac;
  1210. ctlr->get_src_addr = bnx2fc_get_src_mac;
  1211. set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
  1212. rc = bnx2fc_interface_setup(interface);
  1213. if (!rc)
  1214. return interface;
  1215. fcoe_ctlr_destroy(ctlr);
  1216. dev_put(netdev);
  1217. fcoe_ctlr_device_delete(ctlr_dev);
  1218. return NULL;
  1219. }
  1220. /**
  1221. * bnx2fc_if_create - Create FCoE instance on a given interface
  1222. *
  1223. * @interface: FCoE interface to create a local port on
  1224. * @parent: Device pointer to be the parent in sysfs for the SCSI host
  1225. * @npiv: Indicates if the port is vport or not
  1226. *
  1227. * Creates a fc_lport instance and a Scsi_Host instance and configure them.
  1228. *
  1229. * Returns: Allocated fc_lport or an error pointer
  1230. */
  1231. static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
  1232. struct device *parent, int npiv)
  1233. {
  1234. struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
  1235. struct fc_lport *lport, *n_port;
  1236. struct fcoe_port *port;
  1237. struct Scsi_Host *shost;
  1238. struct fc_vport *vport = dev_to_vport(parent);
  1239. struct bnx2fc_lport *blport;
  1240. struct bnx2fc_hba *hba = interface->hba;
  1241. int rc = 0;
  1242. blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
  1243. if (!blport) {
  1244. BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
  1245. return NULL;
  1246. }
  1247. /* Allocate Scsi_Host structure */
  1248. bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
  1249. if (!npiv)
  1250. lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
  1251. else
  1252. lport = libfc_vport_create(vport, sizeof(*port));
  1253. if (!lport) {
  1254. printk(KERN_ERR PFX "could not allocate scsi host structure\n");
  1255. goto free_blport;
  1256. }
  1257. shost = lport->host;
  1258. port = lport_priv(lport);
  1259. port->lport = lport;
  1260. port->priv = interface;
  1261. port->get_netdev = bnx2fc_netdev;
  1262. INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
  1263. /* Configure fcoe_port */
  1264. rc = bnx2fc_lport_config(lport);
  1265. if (rc)
  1266. goto lp_config_err;
  1267. if (npiv) {
  1268. printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
  1269. vport->node_name, vport->port_name);
  1270. fc_set_wwnn(lport, vport->node_name);
  1271. fc_set_wwpn(lport, vport->port_name);
  1272. }
  1273. /* Configure netdev and networking properties of the lport */
  1274. rc = bnx2fc_net_config(lport, interface->netdev);
  1275. if (rc) {
  1276. printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
  1277. goto lp_config_err;
  1278. }
  1279. rc = bnx2fc_shost_config(lport, parent);
  1280. if (rc) {
  1281. printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
  1282. interface->netdev->name);
  1283. goto lp_config_err;
  1284. }
  1285. /* Initialize the libfc library */
  1286. rc = bnx2fc_libfc_config(lport);
  1287. if (rc) {
  1288. printk(KERN_ERR PFX "Couldnt configure libfc\n");
  1289. goto shost_err;
  1290. }
  1291. fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
  1292. /* Allocate exchange manager */
  1293. if (!npiv)
  1294. rc = bnx2fc_em_config(lport, hba);
  1295. else {
  1296. shost = vport_to_shost(vport);
  1297. n_port = shost_priv(shost);
  1298. rc = fc_exch_mgr_list_clone(n_port, lport);
  1299. }
  1300. if (rc) {
  1301. printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
  1302. goto shost_err;
  1303. }
  1304. bnx2fc_interface_get(interface);
  1305. spin_lock_bh(&hba->hba_lock);
  1306. blport->lport = lport;
  1307. list_add_tail(&blport->list, &hba->vports);
  1308. spin_unlock_bh(&hba->hba_lock);
  1309. return lport;
  1310. shost_err:
  1311. scsi_remove_host(shost);
  1312. lp_config_err:
  1313. scsi_host_put(lport->host);
  1314. free_blport:
  1315. kfree(blport);
  1316. return NULL;
  1317. }
  1318. static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
  1319. {
  1320. /* Dont listen for Ethernet packets anymore */
  1321. __dev_remove_pack(&interface->fcoe_packet_type);
  1322. __dev_remove_pack(&interface->fip_packet_type);
  1323. synchronize_net();
  1324. }
  1325. static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
  1326. {
  1327. struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
  1328. struct fc_lport *lport = ctlr->lp;
  1329. struct fcoe_port *port = lport_priv(lport);
  1330. struct bnx2fc_hba *hba = interface->hba;
  1331. /* Stop the transmit retry timer */
  1332. del_timer_sync(&port->timer);
  1333. /* Free existing transmit skbs */
  1334. fcoe_clean_pending_queue(lport);
  1335. bnx2fc_net_cleanup(interface);
  1336. bnx2fc_free_vport(hba, lport);
  1337. }
  1338. static void bnx2fc_if_destroy(struct fc_lport *lport)
  1339. {
  1340. /* Free queued packets for the receive thread */
  1341. bnx2fc_clean_rx_queue(lport);
  1342. /* Detach from scsi-ml */
  1343. fc_remove_host(lport->host);
  1344. scsi_remove_host(lport->host);
  1345. /*
  1346. * Note that only the physical lport will have the exchange manager.
  1347. * for vports, this function is NOP
  1348. */
  1349. fc_exch_mgr_free(lport);
  1350. /* Free memory used by statistical counters */
  1351. fc_lport_free_stats(lport);
  1352. /* Release Scsi_Host */
  1353. scsi_host_put(lport->host);
  1354. }
  1355. static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
  1356. {
  1357. struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
  1358. struct fc_lport *lport = ctlr->lp;
  1359. struct fcoe_port *port = lport_priv(lport);
  1360. bnx2fc_interface_cleanup(interface);
  1361. bnx2fc_stop(interface);
  1362. list_del(&interface->list);
  1363. bnx2fc_interface_put(interface);
  1364. queue_work(bnx2fc_wq, &port->destroy_work);
  1365. }
  1366. /**
  1367. * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
  1368. *
  1369. * @buffer: The name of the Ethernet interface to be destroyed
  1370. * @kp: The associated kernel parameter
  1371. *
  1372. * Called from sysfs.
  1373. *
  1374. * Returns: 0 for success
  1375. */
  1376. static int bnx2fc_destroy(struct net_device *netdev)
  1377. {
  1378. struct bnx2fc_interface *interface = NULL;
  1379. struct workqueue_struct *timer_work_queue;
  1380. struct fcoe_ctlr *ctlr;
  1381. int rc = 0;
  1382. rtnl_lock();
  1383. mutex_lock(&bnx2fc_dev_lock);
  1384. interface = bnx2fc_interface_lookup(netdev);
  1385. ctlr = bnx2fc_to_ctlr(interface);
  1386. if (!interface || !ctlr->lp) {
  1387. rc = -ENODEV;
  1388. printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
  1389. goto netdev_err;
  1390. }
  1391. timer_work_queue = interface->timer_work_queue;
  1392. __bnx2fc_destroy(interface);
  1393. destroy_workqueue(timer_work_queue);
  1394. netdev_err:
  1395. mutex_unlock(&bnx2fc_dev_lock);
  1396. rtnl_unlock();
  1397. return rc;
  1398. }
  1399. static void bnx2fc_destroy_work(struct work_struct *work)
  1400. {
  1401. struct fcoe_port *port;
  1402. struct fc_lport *lport;
  1403. port = container_of(work, struct fcoe_port, destroy_work);
  1404. lport = port->lport;
  1405. BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
  1406. bnx2fc_if_destroy(lport);
  1407. }
  1408. static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
  1409. {
  1410. bnx2fc_free_fw_resc(hba);
  1411. bnx2fc_free_task_ctx(hba);
  1412. }
  1413. /**
  1414. * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
  1415. * pci structure
  1416. *
  1417. * @hba: Adapter instance
  1418. */
  1419. static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
  1420. {
  1421. if (bnx2fc_setup_task_ctx(hba))
  1422. goto mem_err;
  1423. if (bnx2fc_setup_fw_resc(hba))
  1424. goto mem_err;
  1425. return 0;
  1426. mem_err:
  1427. bnx2fc_unbind_adapter_devices(hba);
  1428. return -ENOMEM;
  1429. }
  1430. static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
  1431. {
  1432. struct cnic_dev *cnic;
  1433. struct pci_dev *pdev;
  1434. if (!hba->cnic) {
  1435. printk(KERN_ERR PFX "cnic is NULL\n");
  1436. return -ENODEV;
  1437. }
  1438. cnic = hba->cnic;
  1439. pdev = hba->pcidev = cnic->pcidev;
  1440. if (!hba->pcidev)
  1441. return -ENODEV;
  1442. switch (pdev->device) {
  1443. case PCI_DEVICE_ID_NX2_57710:
  1444. strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
  1445. break;
  1446. case PCI_DEVICE_ID_NX2_57711:
  1447. strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
  1448. break;
  1449. case PCI_DEVICE_ID_NX2_57712:
  1450. case PCI_DEVICE_ID_NX2_57712_MF:
  1451. case PCI_DEVICE_ID_NX2_57712_VF:
  1452. strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
  1453. break;
  1454. case PCI_DEVICE_ID_NX2_57800:
  1455. case PCI_DEVICE_ID_NX2_57800_MF:
  1456. case PCI_DEVICE_ID_NX2_57800_VF:
  1457. strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
  1458. break;
  1459. case PCI_DEVICE_ID_NX2_57810:
  1460. case PCI_DEVICE_ID_NX2_57810_MF:
  1461. case PCI_DEVICE_ID_NX2_57810_VF:
  1462. strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
  1463. break;
  1464. case PCI_DEVICE_ID_NX2_57840:
  1465. case PCI_DEVICE_ID_NX2_57840_MF:
  1466. case PCI_DEVICE_ID_NX2_57840_VF:
  1467. case PCI_DEVICE_ID_NX2_57840_2_20:
  1468. case PCI_DEVICE_ID_NX2_57840_4_10:
  1469. strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
  1470. break;
  1471. default:
  1472. pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
  1473. break;
  1474. }
  1475. pci_dev_get(hba->pcidev);
  1476. return 0;
  1477. }
  1478. static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
  1479. {
  1480. if (hba->pcidev) {
  1481. hba->chip_num[0] = '\0';
  1482. pci_dev_put(hba->pcidev);
  1483. }
  1484. hba->pcidev = NULL;
  1485. }
  1486. /**
  1487. * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
  1488. *
  1489. * @handle: transport handle pointing to adapter struture
  1490. */
  1491. static int bnx2fc_ulp_get_stats(void *handle)
  1492. {
  1493. struct bnx2fc_hba *hba = handle;
  1494. struct cnic_dev *cnic;
  1495. struct fcoe_stats_info *stats_addr;
  1496. if (!hba)
  1497. return -EINVAL;
  1498. cnic = hba->cnic;
  1499. stats_addr = &cnic->stats_addr->fcoe_stat;
  1500. if (!stats_addr)
  1501. return -EINVAL;
  1502. strncpy(stats_addr->version, BNX2FC_VERSION,
  1503. sizeof(stats_addr->version));
  1504. stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
  1505. stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
  1506. return 0;
  1507. }
  1508. /**
  1509. * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
  1510. *
  1511. * @handle: transport handle pointing to adapter structure
  1512. *
  1513. * This function maps adapter structure to pcidev structure and initiates
  1514. * firmware handshake to enable/initialize on-chip FCoE components.
  1515. * This bnx2fc - cnic interface api callback is used after following
  1516. * conditions are met -
  1517. * a) underlying network interface is up (marked by event NETDEV_UP
  1518. * from netdev
  1519. * b) bnx2fc adatper structure is registered.
  1520. */
  1521. static void bnx2fc_ulp_start(void *handle)
  1522. {
  1523. struct bnx2fc_hba *hba = handle;
  1524. struct bnx2fc_interface *interface;
  1525. struct fcoe_ctlr *ctlr;
  1526. struct fc_lport *lport;
  1527. mutex_lock(&bnx2fc_dev_lock);
  1528. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
  1529. bnx2fc_fw_init(hba);
  1530. BNX2FC_MISC_DBG("bnx2fc started.\n");
  1531. list_for_each_entry(interface, &if_list, list) {
  1532. if (interface->hba == hba) {
  1533. ctlr = bnx2fc_to_ctlr(interface);
  1534. lport = ctlr->lp;
  1535. /* Kick off Fabric discovery*/
  1536. printk(KERN_ERR PFX "ulp_init: start discovery\n");
  1537. lport->tt.frame_send = bnx2fc_xmit;
  1538. bnx2fc_start_disc(interface);
  1539. }
  1540. }
  1541. mutex_unlock(&bnx2fc_dev_lock);
  1542. }
  1543. static void bnx2fc_port_shutdown(struct fc_lport *lport)
  1544. {
  1545. BNX2FC_MISC_DBG("Entered %s\n", __func__);
  1546. fc_fabric_logoff(lport);
  1547. fc_lport_destroy(lport);
  1548. }
  1549. static void bnx2fc_stop(struct bnx2fc_interface *interface)
  1550. {
  1551. struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
  1552. struct fc_lport *lport;
  1553. struct fc_lport *vport;
  1554. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
  1555. return;
  1556. lport = ctlr->lp;
  1557. bnx2fc_port_shutdown(lport);
  1558. mutex_lock(&lport->lp_mutex);
  1559. list_for_each_entry(vport, &lport->vports, list)
  1560. fc_host_port_type(vport->host) =
  1561. FC_PORTTYPE_UNKNOWN;
  1562. mutex_unlock(&lport->lp_mutex);
  1563. fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
  1564. fcoe_ctlr_link_down(ctlr);
  1565. fcoe_clean_pending_queue(lport);
  1566. }
  1567. static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
  1568. {
  1569. #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
  1570. int rc = -1;
  1571. int i = HZ;
  1572. rc = bnx2fc_bind_adapter_devices(hba);
  1573. if (rc) {
  1574. printk(KERN_ALERT PFX
  1575. "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
  1576. goto err_out;
  1577. }
  1578. rc = bnx2fc_send_fw_fcoe_init_msg(hba);
  1579. if (rc) {
  1580. printk(KERN_ALERT PFX
  1581. "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
  1582. goto err_unbind;
  1583. }
  1584. /*
  1585. * Wait until the adapter init message is complete, and adapter
  1586. * state is UP.
  1587. */
  1588. while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
  1589. msleep(BNX2FC_INIT_POLL_TIME);
  1590. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
  1591. printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
  1592. "Ignoring...\n",
  1593. hba->cnic->netdev->name);
  1594. rc = -1;
  1595. goto err_unbind;
  1596. }
  1597. set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
  1598. return 0;
  1599. err_unbind:
  1600. bnx2fc_unbind_adapter_devices(hba);
  1601. err_out:
  1602. return rc;
  1603. }
  1604. static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
  1605. {
  1606. if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
  1607. if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
  1608. init_timer(&hba->destroy_timer);
  1609. hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
  1610. jiffies;
  1611. hba->destroy_timer.function = bnx2fc_destroy_timer;
  1612. hba->destroy_timer.data = (unsigned long)hba;
  1613. add_timer(&hba->destroy_timer);
  1614. wait_event_interruptible(hba->destroy_wait,
  1615. test_bit(BNX2FC_FLAG_DESTROY_CMPL,
  1616. &hba->flags));
  1617. clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
  1618. /* This should never happen */
  1619. if (signal_pending(current))
  1620. flush_signals(current);
  1621. del_timer_sync(&hba->destroy_timer);
  1622. }
  1623. bnx2fc_unbind_adapter_devices(hba);
  1624. }
  1625. }
  1626. /**
  1627. * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
  1628. *
  1629. * @handle: transport handle pointing to adapter structure
  1630. *
  1631. * Driver checks if adapter is already in shutdown mode, if not start
  1632. * the shutdown process.
  1633. */
  1634. static void bnx2fc_ulp_stop(void *handle)
  1635. {
  1636. struct bnx2fc_hba *hba = handle;
  1637. struct bnx2fc_interface *interface;
  1638. printk(KERN_ERR "ULP_STOP\n");
  1639. mutex_lock(&bnx2fc_dev_lock);
  1640. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
  1641. goto exit;
  1642. list_for_each_entry(interface, &if_list, list) {
  1643. if (interface->hba == hba)
  1644. bnx2fc_stop(interface);
  1645. }
  1646. BUG_ON(hba->num_ofld_sess != 0);
  1647. mutex_lock(&hba->hba_mutex);
  1648. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  1649. clear_bit(ADAPTER_STATE_GOING_DOWN,
  1650. &hba->adapter_state);
  1651. clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
  1652. mutex_unlock(&hba->hba_mutex);
  1653. bnx2fc_fw_destroy(hba);
  1654. exit:
  1655. mutex_unlock(&bnx2fc_dev_lock);
  1656. }
  1657. static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
  1658. {
  1659. struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
  1660. struct fc_lport *lport;
  1661. int wait_cnt = 0;
  1662. BNX2FC_MISC_DBG("Entered %s\n", __func__);
  1663. /* Kick off FIP/FLOGI */
  1664. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
  1665. printk(KERN_ERR PFX "Init not done yet\n");
  1666. return;
  1667. }
  1668. lport = ctlr->lp;
  1669. BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
  1670. if (!bnx2fc_link_ok(lport) && interface->enabled) {
  1671. BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
  1672. fcoe_ctlr_link_up(ctlr);
  1673. fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
  1674. set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
  1675. }
  1676. /* wait for the FCF to be selected before issuing FLOGI */
  1677. while (!ctlr->sel_fcf) {
  1678. msleep(250);
  1679. /* give up after 3 secs */
  1680. if (++wait_cnt > 12)
  1681. break;
  1682. }
  1683. /* Reset max receive frame size to default */
  1684. if (fc_set_mfs(lport, BNX2FC_MFS))
  1685. return;
  1686. fc_lport_init(lport);
  1687. fc_fabric_login(lport);
  1688. }
  1689. /**
  1690. * bnx2fc_ulp_init - Initialize an adapter instance
  1691. *
  1692. * @dev : cnic device handle
  1693. * Called from cnic_register_driver() context to initialize all
  1694. * enumerated cnic devices. This routine allocates adapter structure
  1695. * and other device specific resources.
  1696. */
  1697. static void bnx2fc_ulp_init(struct cnic_dev *dev)
  1698. {
  1699. struct bnx2fc_hba *hba;
  1700. int rc = 0;
  1701. BNX2FC_MISC_DBG("Entered %s\n", __func__);
  1702. /* bnx2fc works only when bnx2x is loaded */
  1703. if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
  1704. (dev->max_fcoe_conn == 0)) {
  1705. printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
  1706. " flags: %lx fcoe_conn: %d\n",
  1707. dev->netdev->name, dev->flags, dev->max_fcoe_conn);
  1708. return;
  1709. }
  1710. hba = bnx2fc_hba_create(dev);
  1711. if (!hba) {
  1712. printk(KERN_ERR PFX "hba initialization failed\n");
  1713. return;
  1714. }
  1715. /* Add HBA to the adapter list */
  1716. mutex_lock(&bnx2fc_dev_lock);
  1717. list_add_tail(&hba->list, &adapter_list);
  1718. adapter_count++;
  1719. mutex_unlock(&bnx2fc_dev_lock);
  1720. dev->fcoe_cap = &hba->fcoe_cap;
  1721. clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
  1722. rc = dev->register_device(dev, CNIC_ULP_FCOE,
  1723. (void *) hba);
  1724. if (rc)
  1725. printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
  1726. else
  1727. set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
  1728. }
  1729. /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
  1730. static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
  1731. {
  1732. struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
  1733. if (interface->enabled == true) {
  1734. if (!ctlr->lp) {
  1735. pr_err(PFX "__bnx2fc_disable: lport not found\n");
  1736. return -ENODEV;
  1737. } else {
  1738. interface->enabled = false;
  1739. fcoe_ctlr_link_down(ctlr);
  1740. fcoe_clean_pending_queue(ctlr->lp);
  1741. }
  1742. }
  1743. return 0;
  1744. }
  1745. /**
  1746. * Deperecated: Use bnx2fc_enabled()
  1747. */
  1748. static int bnx2fc_disable(struct net_device *netdev)
  1749. {
  1750. struct bnx2fc_interface *interface;
  1751. struct fcoe_ctlr *ctlr;
  1752. int rc = 0;
  1753. rtnl_lock();
  1754. mutex_lock(&bnx2fc_dev_lock);
  1755. interface = bnx2fc_interface_lookup(netdev);
  1756. ctlr = bnx2fc_to_ctlr(interface);
  1757. if (!interface) {
  1758. rc = -ENODEV;
  1759. pr_err(PFX "bnx2fc_disable: interface not found\n");
  1760. } else {
  1761. rc = __bnx2fc_disable(ctlr);
  1762. }
  1763. mutex_unlock(&bnx2fc_dev_lock);
  1764. rtnl_unlock();
  1765. return rc;
  1766. }
  1767. static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
  1768. struct cnic_fc_npiv_tbl *npiv_tbl)
  1769. {
  1770. struct fc_vport_identifiers vpid;
  1771. uint i, created = 0;
  1772. if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
  1773. BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
  1774. goto done;
  1775. }
  1776. /* Sanity check the first entry to make sure it's not 0 */
  1777. if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
  1778. wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
  1779. BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
  1780. goto done;
  1781. }
  1782. vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
  1783. vpid.vport_type = FC_PORTTYPE_NPIV;
  1784. vpid.disable = false;
  1785. for (i = 0; i < npiv_tbl->count; i++) {
  1786. vpid.node_name = wwn_to_u64(npiv_tbl->wwnn[i]);
  1787. vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
  1788. scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
  1789. "NPIV[%u]:%016llx-%016llx",
  1790. created, vpid.port_name, vpid.node_name);
  1791. if (fc_vport_create(lport->host, 0, &vpid))
  1792. created++;
  1793. else
  1794. BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
  1795. }
  1796. done:
  1797. return created;
  1798. }
  1799. static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
  1800. {
  1801. struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
  1802. struct bnx2fc_hba *hba;
  1803. struct cnic_fc_npiv_tbl *npiv_tbl;
  1804. struct fc_lport *lport;
  1805. if (interface->enabled == false) {
  1806. if (!ctlr->lp) {
  1807. pr_err(PFX "__bnx2fc_enable: lport not found\n");
  1808. return -ENODEV;
  1809. } else if (!bnx2fc_link_ok(ctlr->lp)) {
  1810. fcoe_ctlr_link_up(ctlr);
  1811. interface->enabled = true;
  1812. }
  1813. }
  1814. /* Create static NPIV ports if any are contained in NVRAM */
  1815. hba = interface->hba;
  1816. lport = ctlr->lp;
  1817. if (!hba)
  1818. goto done;
  1819. if (!hba->cnic)
  1820. goto done;
  1821. if (!lport)
  1822. goto done;
  1823. if (!lport->host)
  1824. goto done;
  1825. if (!hba->cnic->get_fc_npiv_tbl)
  1826. goto done;
  1827. npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
  1828. if (!npiv_tbl)
  1829. goto done;
  1830. if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
  1831. goto done_free;
  1832. bnx2fc_npiv_create_vports(lport, npiv_tbl);
  1833. done_free:
  1834. kfree(npiv_tbl);
  1835. done:
  1836. return 0;
  1837. }
  1838. /**
  1839. * Deprecated: Use bnx2fc_enabled()
  1840. */
  1841. static int bnx2fc_enable(struct net_device *netdev)
  1842. {
  1843. struct bnx2fc_interface *interface;
  1844. struct fcoe_ctlr *ctlr;
  1845. int rc = 0;
  1846. rtnl_lock();
  1847. mutex_lock(&bnx2fc_dev_lock);
  1848. interface = bnx2fc_interface_lookup(netdev);
  1849. ctlr = bnx2fc_to_ctlr(interface);
  1850. if (!interface) {
  1851. rc = -ENODEV;
  1852. pr_err(PFX "bnx2fc_enable: interface not found\n");
  1853. } else {
  1854. rc = __bnx2fc_enable(ctlr);
  1855. }
  1856. mutex_unlock(&bnx2fc_dev_lock);
  1857. rtnl_unlock();
  1858. return rc;
  1859. }
  1860. /**
  1861. * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
  1862. * @cdev: The FCoE Controller that is being enabled or disabled
  1863. *
  1864. * fcoe_sysfs will ensure that the state of 'enabled' has
  1865. * changed, so no checking is necessary here. This routine simply
  1866. * calls fcoe_enable or fcoe_disable, both of which are deprecated.
  1867. * When those routines are removed the functionality can be merged
  1868. * here.
  1869. */
  1870. static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
  1871. {
  1872. struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
  1873. switch (cdev->enabled) {
  1874. case FCOE_CTLR_ENABLED:
  1875. return __bnx2fc_enable(ctlr);
  1876. case FCOE_CTLR_DISABLED:
  1877. return __bnx2fc_disable(ctlr);
  1878. case FCOE_CTLR_UNUSED:
  1879. default:
  1880. return -ENOTSUPP;
  1881. };
  1882. }
  1883. enum bnx2fc_create_link_state {
  1884. BNX2FC_CREATE_LINK_DOWN,
  1885. BNX2FC_CREATE_LINK_UP,
  1886. };
  1887. /**
  1888. * _bnx2fc_create() - Create bnx2fc FCoE interface
  1889. * @netdev : The net_device object the Ethernet interface to create on
  1890. * @fip_mode: The FIP mode for this creation
  1891. * @link_state: The ctlr link state on creation
  1892. *
  1893. * Called from either the libfcoe 'create' module parameter
  1894. * via fcoe_create or from fcoe_syfs's ctlr_create file.
  1895. *
  1896. * libfcoe's 'create' module parameter is deprecated so some
  1897. * consolidation of code can be done when that interface is
  1898. * removed.
  1899. *
  1900. * Returns: 0 for success
  1901. */
  1902. static int _bnx2fc_create(struct net_device *netdev,
  1903. enum fip_state fip_mode,
  1904. enum bnx2fc_create_link_state link_state)
  1905. {
  1906. struct fcoe_ctlr_device *cdev;
  1907. struct fcoe_ctlr *ctlr;
  1908. struct bnx2fc_interface *interface;
  1909. struct bnx2fc_hba *hba;
  1910. struct net_device *phys_dev = netdev;
  1911. struct fc_lport *lport;
  1912. struct ethtool_drvinfo drvinfo;
  1913. int rc = 0;
  1914. int vlan_id = 0;
  1915. BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
  1916. if (fip_mode != FIP_MODE_FABRIC) {
  1917. printk(KERN_ERR "fip mode not FABRIC\n");
  1918. return -EIO;
  1919. }
  1920. rtnl_lock();
  1921. mutex_lock(&bnx2fc_dev_lock);
  1922. if (!try_module_get(THIS_MODULE)) {
  1923. rc = -EINVAL;
  1924. goto mod_err;
  1925. }
  1926. /* obtain physical netdev */
  1927. if (netdev->priv_flags & IFF_802_1Q_VLAN)
  1928. phys_dev = vlan_dev_real_dev(netdev);
  1929. /* verify if the physical device is a netxtreme2 device */
  1930. if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
  1931. memset(&drvinfo, 0, sizeof(drvinfo));
  1932. phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
  1933. if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
  1934. printk(KERN_ERR PFX "Not a netxtreme2 device\n");
  1935. rc = -EINVAL;
  1936. goto netdev_err;
  1937. }
  1938. } else {
  1939. printk(KERN_ERR PFX "unable to obtain drv_info\n");
  1940. rc = -EINVAL;
  1941. goto netdev_err;
  1942. }
  1943. /* obtain interface and initialize rest of the structure */
  1944. hba = bnx2fc_hba_lookup(phys_dev);
  1945. if (!hba) {
  1946. rc = -ENODEV;
  1947. printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
  1948. goto netdev_err;
  1949. }
  1950. if (bnx2fc_interface_lookup(netdev)) {
  1951. rc = -EEXIST;
  1952. goto netdev_err;
  1953. }
  1954. interface = bnx2fc_interface_create(hba, netdev, fip_mode);
  1955. if (!interface) {
  1956. printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
  1957. rc = -ENOMEM;
  1958. goto netdev_err;
  1959. }
  1960. if (netdev->priv_flags & IFF_802_1Q_VLAN) {
  1961. vlan_id = vlan_dev_vlan_id(netdev);
  1962. interface->vlan_enabled = 1;
  1963. }
  1964. ctlr = bnx2fc_to_ctlr(interface);
  1965. cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
  1966. interface->vlan_id = vlan_id;
  1967. interface->timer_work_queue =
  1968. create_singlethread_workqueue("bnx2fc_timer_wq");
  1969. if (!interface->timer_work_queue) {
  1970. printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
  1971. rc = -EINVAL;
  1972. goto ifput_err;
  1973. }
  1974. lport = bnx2fc_if_create(interface, &cdev->dev, 0);
  1975. if (!lport) {
  1976. printk(KERN_ERR PFX "Failed to create interface (%s)\n",
  1977. netdev->name);
  1978. rc = -EINVAL;
  1979. goto if_create_err;
  1980. }
  1981. /* Add interface to if_list */
  1982. list_add_tail(&interface->list, &if_list);
  1983. lport->boot_time = jiffies;
  1984. /* Make this master N_port */
  1985. ctlr->lp = lport;
  1986. if (link_state == BNX2FC_CREATE_LINK_UP)
  1987. cdev->enabled = FCOE_CTLR_ENABLED;
  1988. else
  1989. cdev->enabled = FCOE_CTLR_DISABLED;
  1990. if (link_state == BNX2FC_CREATE_LINK_UP &&
  1991. !bnx2fc_link_ok(lport)) {
  1992. fcoe_ctlr_link_up(ctlr);
  1993. fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
  1994. set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
  1995. }
  1996. BNX2FC_HBA_DBG(lport, "create: START DISC\n");
  1997. bnx2fc_start_disc(interface);
  1998. if (link_state == BNX2FC_CREATE_LINK_UP)
  1999. interface->enabled = true;
  2000. /*
  2001. * Release from kref_init in bnx2fc_interface_setup, on success
  2002. * lport should be holding a reference taken in bnx2fc_if_create
  2003. */
  2004. bnx2fc_interface_put(interface);
  2005. /* put netdev that was held while calling dev_get_by_name */
  2006. mutex_unlock(&bnx2fc_dev_lock);
  2007. rtnl_unlock();
  2008. return 0;
  2009. if_create_err:
  2010. destroy_workqueue(interface->timer_work_queue);
  2011. ifput_err:
  2012. bnx2fc_net_cleanup(interface);
  2013. bnx2fc_interface_put(interface);
  2014. goto mod_err;
  2015. netdev_err:
  2016. module_put(THIS_MODULE);
  2017. mod_err:
  2018. mutex_unlock(&bnx2fc_dev_lock);
  2019. rtnl_unlock();
  2020. return rc;
  2021. }
  2022. /**
  2023. * bnx2fc_create() - Create a bnx2fc interface
  2024. * @netdev : The net_device object the Ethernet interface to create on
  2025. * @fip_mode: The FIP mode for this creation
  2026. *
  2027. * Called from fcoe transport
  2028. *
  2029. * Returns: 0 for success
  2030. */
  2031. static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
  2032. {
  2033. return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
  2034. }
  2035. /**
  2036. * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
  2037. * @netdev: The net_device to be used by the allocated FCoE Controller
  2038. *
  2039. * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
  2040. * in a link_down state. The allows the user an opportunity to configure
  2041. * the FCoE Controller from sysfs before enabling the FCoE Controller.
  2042. *
  2043. * Creating in with this routine starts the FCoE Controller in Fabric
  2044. * mode. The user can change to VN2VN or another mode before enabling.
  2045. */
  2046. static int bnx2fc_ctlr_alloc(struct net_device *netdev)
  2047. {
  2048. return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
  2049. BNX2FC_CREATE_LINK_DOWN);
  2050. }
  2051. /**
  2052. * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
  2053. *
  2054. * @cnic: Pointer to cnic device instance
  2055. *
  2056. **/
  2057. static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
  2058. {
  2059. struct bnx2fc_hba *hba;
  2060. /* Called with bnx2fc_dev_lock held */
  2061. list_for_each_entry(hba, &adapter_list, list) {
  2062. if (hba->cnic == cnic)
  2063. return hba;
  2064. }
  2065. return NULL;
  2066. }
  2067. static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
  2068. *netdev)
  2069. {
  2070. struct bnx2fc_interface *interface;
  2071. /* Called with bnx2fc_dev_lock held */
  2072. list_for_each_entry(interface, &if_list, list) {
  2073. if (interface->netdev == netdev)
  2074. return interface;
  2075. }
  2076. return NULL;
  2077. }
  2078. static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
  2079. *phys_dev)
  2080. {
  2081. struct bnx2fc_hba *hba;
  2082. /* Called with bnx2fc_dev_lock held */
  2083. list_for_each_entry(hba, &adapter_list, list) {
  2084. if (hba->phys_dev == phys_dev)
  2085. return hba;
  2086. }
  2087. printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
  2088. return NULL;
  2089. }
  2090. /**
  2091. * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
  2092. *
  2093. * @dev cnic device handle
  2094. */
  2095. static void bnx2fc_ulp_exit(struct cnic_dev *dev)
  2096. {
  2097. struct bnx2fc_hba *hba;
  2098. struct bnx2fc_interface *interface, *tmp;
  2099. BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
  2100. if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
  2101. printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
  2102. dev->netdev->name, dev->flags);
  2103. return;
  2104. }
  2105. mutex_lock(&bnx2fc_dev_lock);
  2106. hba = bnx2fc_find_hba_for_cnic(dev);
  2107. if (!hba) {
  2108. printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
  2109. dev);
  2110. mutex_unlock(&bnx2fc_dev_lock);
  2111. return;
  2112. }
  2113. list_del_init(&hba->list);
  2114. adapter_count--;
  2115. list_for_each_entry_safe(interface, tmp, &if_list, list)
  2116. /* destroy not called yet, move to quiesced list */
  2117. if (interface->hba == hba)
  2118. __bnx2fc_destroy(interface);
  2119. mutex_unlock(&bnx2fc_dev_lock);
  2120. /* Ensure ALL destroy work has been completed before return */
  2121. flush_workqueue(bnx2fc_wq);
  2122. bnx2fc_ulp_stop(hba);
  2123. /* unregister cnic device */
  2124. if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
  2125. hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
  2126. bnx2fc_hba_destroy(hba);
  2127. }
  2128. /**
  2129. * bnx2fc_fcoe_reset - Resets the fcoe
  2130. *
  2131. * @shost: shost the reset is from
  2132. *
  2133. * Returns: always 0
  2134. */
  2135. static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
  2136. {
  2137. struct fc_lport *lport = shost_priv(shost);
  2138. fc_lport_reset(lport);
  2139. return 0;
  2140. }
  2141. static bool bnx2fc_match(struct net_device *netdev)
  2142. {
  2143. struct net_device *phys_dev = netdev;
  2144. mutex_lock(&bnx2fc_dev_lock);
  2145. if (netdev->priv_flags & IFF_802_1Q_VLAN)
  2146. phys_dev = vlan_dev_real_dev(netdev);
  2147. if (bnx2fc_hba_lookup(phys_dev)) {
  2148. mutex_unlock(&bnx2fc_dev_lock);
  2149. return true;
  2150. }
  2151. mutex_unlock(&bnx2fc_dev_lock);
  2152. return false;
  2153. }
  2154. static struct fcoe_transport bnx2fc_transport = {
  2155. .name = {"bnx2fc"},
  2156. .attached = false,
  2157. .list = LIST_HEAD_INIT(bnx2fc_transport.list),
  2158. .alloc = bnx2fc_ctlr_alloc,
  2159. .match = bnx2fc_match,
  2160. .create = bnx2fc_create,
  2161. .destroy = bnx2fc_destroy,
  2162. .enable = bnx2fc_enable,
  2163. .disable = bnx2fc_disable,
  2164. };
  2165. /**
  2166. * bnx2fc_percpu_thread_create - Create a receive thread for an
  2167. * online CPU
  2168. *
  2169. * @cpu: cpu index for the online cpu
  2170. */
  2171. static void bnx2fc_percpu_thread_create(unsigned int cpu)
  2172. {
  2173. struct bnx2fc_percpu_s *p;
  2174. struct task_struct *thread;
  2175. p = &per_cpu(bnx2fc_percpu, cpu);
  2176. thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
  2177. (void *)p, cpu_to_node(cpu),
  2178. "bnx2fc_thread/%d", cpu);
  2179. /* bind thread to the cpu */
  2180. if (likely(!IS_ERR(thread))) {
  2181. kthread_bind(thread, cpu);
  2182. p->iothread = thread;
  2183. wake_up_process(thread);
  2184. }
  2185. }
  2186. static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
  2187. {
  2188. struct bnx2fc_percpu_s *p;
  2189. struct task_struct *thread;
  2190. struct bnx2fc_work *work, *tmp;
  2191. BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
  2192. /* Prevent any new work from being queued for this CPU */
  2193. p = &per_cpu(bnx2fc_percpu, cpu);
  2194. spin_lock_bh(&p->fp_work_lock);
  2195. thread = p->iothread;
  2196. p->iothread = NULL;
  2197. /* Free all work in the list */
  2198. list_for_each_entry_safe(work, tmp, &p->work_list, list) {
  2199. list_del_init(&work->list);
  2200. bnx2fc_process_cq_compl(work->tgt, work->wqe);
  2201. kfree(work);
  2202. }
  2203. spin_unlock_bh(&p->fp_work_lock);
  2204. if (thread)
  2205. kthread_stop(thread);
  2206. }
  2207. /**
  2208. * bnx2fc_cpu_callback - Handler for CPU hotplug events
  2209. *
  2210. * @nfb: The callback data block
  2211. * @action: The event triggering the callback
  2212. * @hcpu: The index of the CPU that the event is for
  2213. *
  2214. * This creates or destroys per-CPU data for fcoe
  2215. *
  2216. * Returns NOTIFY_OK always.
  2217. */
  2218. static int bnx2fc_cpu_callback(struct notifier_block *nfb,
  2219. unsigned long action, void *hcpu)
  2220. {
  2221. unsigned cpu = (unsigned long)hcpu;
  2222. switch (action) {
  2223. case CPU_ONLINE:
  2224. case CPU_ONLINE_FROZEN:
  2225. printk(PFX "CPU %x online: Create Rx thread\n", cpu);
  2226. bnx2fc_percpu_thread_create(cpu);
  2227. break;
  2228. case CPU_DEAD:
  2229. case CPU_DEAD_FROZEN:
  2230. printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
  2231. bnx2fc_percpu_thread_destroy(cpu);
  2232. break;
  2233. default:
  2234. break;
  2235. }
  2236. return NOTIFY_OK;
  2237. }
  2238. /**
  2239. * bnx2fc_mod_init - module init entry point
  2240. *
  2241. * Initialize driver wide global data structures, and register
  2242. * with cnic module
  2243. **/
  2244. static int __init bnx2fc_mod_init(void)
  2245. {
  2246. struct fcoe_percpu_s *bg;
  2247. struct task_struct *l2_thread;
  2248. int rc = 0;
  2249. unsigned int cpu = 0;
  2250. struct bnx2fc_percpu_s *p;
  2251. printk(KERN_INFO PFX "%s", version);
  2252. /* register as a fcoe transport */
  2253. rc = fcoe_transport_attach(&bnx2fc_transport);
  2254. if (rc) {
  2255. printk(KERN_ERR "failed to register an fcoe transport, check "
  2256. "if libfcoe is loaded\n");
  2257. goto out;
  2258. }
  2259. INIT_LIST_HEAD(&adapter_list);
  2260. INIT_LIST_HEAD(&if_list);
  2261. mutex_init(&bnx2fc_dev_lock);
  2262. adapter_count = 0;
  2263. /* Attach FC transport template */
  2264. rc = bnx2fc_attach_transport();
  2265. if (rc)
  2266. goto detach_ft;
  2267. bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
  2268. if (!bnx2fc_wq) {
  2269. rc = -ENOMEM;
  2270. goto release_bt;
  2271. }
  2272. bg = &bnx2fc_global;
  2273. skb_queue_head_init(&bg->fcoe_rx_list);
  2274. l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
  2275. (void *)bg,
  2276. "bnx2fc_l2_thread");
  2277. if (IS_ERR(l2_thread)) {
  2278. rc = PTR_ERR(l2_thread);
  2279. goto free_wq;
  2280. }
  2281. wake_up_process(l2_thread);
  2282. spin_lock_bh(&bg->fcoe_rx_list.lock);
  2283. bg->thread = l2_thread;
  2284. spin_unlock_bh(&bg->fcoe_rx_list.lock);
  2285. for_each_possible_cpu(cpu) {
  2286. p = &per_cpu(bnx2fc_percpu, cpu);
  2287. INIT_LIST_HEAD(&p->work_list);
  2288. spin_lock_init(&p->fp_work_lock);
  2289. }
  2290. cpu_notifier_register_begin();
  2291. for_each_online_cpu(cpu) {
  2292. bnx2fc_percpu_thread_create(cpu);
  2293. }
  2294. /* Initialize per CPU interrupt thread */
  2295. __register_hotcpu_notifier(&bnx2fc_cpu_notifier);
  2296. cpu_notifier_register_done();
  2297. cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
  2298. return 0;
  2299. free_wq:
  2300. destroy_workqueue(bnx2fc_wq);
  2301. release_bt:
  2302. bnx2fc_release_transport();
  2303. detach_ft:
  2304. fcoe_transport_detach(&bnx2fc_transport);
  2305. out:
  2306. return rc;
  2307. }
  2308. static void __exit bnx2fc_mod_exit(void)
  2309. {
  2310. LIST_HEAD(to_be_deleted);
  2311. struct bnx2fc_hba *hba, *next;
  2312. struct fcoe_percpu_s *bg;
  2313. struct task_struct *l2_thread;
  2314. struct sk_buff *skb;
  2315. unsigned int cpu = 0;
  2316. /*
  2317. * NOTE: Since cnic calls register_driver routine rtnl_lock,
  2318. * it will have higher precedence than bnx2fc_dev_lock.
  2319. * unregister_device() cannot be called with bnx2fc_dev_lock
  2320. * held.
  2321. */
  2322. mutex_lock(&bnx2fc_dev_lock);
  2323. list_splice(&adapter_list, &to_be_deleted);
  2324. INIT_LIST_HEAD(&adapter_list);
  2325. adapter_count = 0;
  2326. mutex_unlock(&bnx2fc_dev_lock);
  2327. /* Unregister with cnic */
  2328. list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
  2329. list_del_init(&hba->list);
  2330. printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
  2331. hba);
  2332. bnx2fc_ulp_stop(hba);
  2333. /* unregister cnic device */
  2334. if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
  2335. &hba->reg_with_cnic))
  2336. hba->cnic->unregister_device(hba->cnic,
  2337. CNIC_ULP_FCOE);
  2338. bnx2fc_hba_destroy(hba);
  2339. }
  2340. cnic_unregister_driver(CNIC_ULP_FCOE);
  2341. /* Destroy global thread */
  2342. bg = &bnx2fc_global;
  2343. spin_lock_bh(&bg->fcoe_rx_list.lock);
  2344. l2_thread = bg->thread;
  2345. bg->thread = NULL;
  2346. while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
  2347. kfree_skb(skb);
  2348. spin_unlock_bh(&bg->fcoe_rx_list.lock);
  2349. if (l2_thread)
  2350. kthread_stop(l2_thread);
  2351. cpu_notifier_register_begin();
  2352. /* Destroy per cpu threads */
  2353. for_each_online_cpu(cpu) {
  2354. bnx2fc_percpu_thread_destroy(cpu);
  2355. }
  2356. __unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
  2357. cpu_notifier_register_done();
  2358. destroy_workqueue(bnx2fc_wq);
  2359. /*
  2360. * detach from scsi transport
  2361. * must happen after all destroys are done
  2362. */
  2363. bnx2fc_release_transport();
  2364. /* detach from fcoe transport */
  2365. fcoe_transport_detach(&bnx2fc_transport);
  2366. }
  2367. module_init(bnx2fc_mod_init);
  2368. module_exit(bnx2fc_mod_exit);
  2369. static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
  2370. .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
  2371. .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
  2372. .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
  2373. .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
  2374. .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
  2375. .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
  2376. .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
  2377. .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
  2378. .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
  2379. };
  2380. static struct fc_function_template bnx2fc_transport_function = {
  2381. .show_host_node_name = 1,
  2382. .show_host_port_name = 1,
  2383. .show_host_supported_classes = 1,
  2384. .show_host_supported_fc4s = 1,
  2385. .show_host_active_fc4s = 1,
  2386. .show_host_maxframe_size = 1,
  2387. .show_host_port_id = 1,
  2388. .show_host_supported_speeds = 1,
  2389. .get_host_speed = fc_get_host_speed,
  2390. .show_host_speed = 1,
  2391. .show_host_port_type = 1,
  2392. .get_host_port_state = fc_get_host_port_state,
  2393. .show_host_port_state = 1,
  2394. .show_host_symbolic_name = 1,
  2395. .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
  2396. sizeof(struct bnx2fc_rport)),
  2397. .show_rport_maxframe_size = 1,
  2398. .show_rport_supported_classes = 1,
  2399. .show_host_fabric_name = 1,
  2400. .show_starget_node_name = 1,
  2401. .show_starget_port_name = 1,
  2402. .show_starget_port_id = 1,
  2403. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  2404. .show_rport_dev_loss_tmo = 1,
  2405. .get_fc_host_stats = bnx2fc_get_host_stats,
  2406. .issue_fc_host_lip = bnx2fc_fcoe_reset,
  2407. .terminate_rport_io = fc_rport_terminate_io,
  2408. .vport_create = bnx2fc_vport_create,
  2409. .vport_delete = bnx2fc_vport_destroy,
  2410. .vport_disable = bnx2fc_vport_disable,
  2411. .bsg_request = fc_lport_bsg_request,
  2412. };
  2413. static struct fc_function_template bnx2fc_vport_xport_function = {
  2414. .show_host_node_name = 1,
  2415. .show_host_port_name = 1,
  2416. .show_host_supported_classes = 1,
  2417. .show_host_supported_fc4s = 1,
  2418. .show_host_active_fc4s = 1,
  2419. .show_host_maxframe_size = 1,
  2420. .show_host_port_id = 1,
  2421. .show_host_supported_speeds = 1,
  2422. .get_host_speed = fc_get_host_speed,
  2423. .show_host_speed = 1,
  2424. .show_host_port_type = 1,
  2425. .get_host_port_state = fc_get_host_port_state,
  2426. .show_host_port_state = 1,
  2427. .show_host_symbolic_name = 1,
  2428. .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
  2429. sizeof(struct bnx2fc_rport)),
  2430. .show_rport_maxframe_size = 1,
  2431. .show_rport_supported_classes = 1,
  2432. .show_host_fabric_name = 1,
  2433. .show_starget_node_name = 1,
  2434. .show_starget_port_name = 1,
  2435. .show_starget_port_id = 1,
  2436. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  2437. .show_rport_dev_loss_tmo = 1,
  2438. .get_fc_host_stats = fc_get_host_stats,
  2439. .issue_fc_host_lip = bnx2fc_fcoe_reset,
  2440. .terminate_rport_io = fc_rport_terminate_io,
  2441. .bsg_request = fc_lport_bsg_request,
  2442. };
  2443. /**
  2444. * scsi_host_template structure used while registering with SCSI-ml
  2445. */
  2446. static struct scsi_host_template bnx2fc_shost_template = {
  2447. .module = THIS_MODULE,
  2448. .name = "QLogic Offload FCoE Initiator",
  2449. .queuecommand = bnx2fc_queuecommand,
  2450. .eh_abort_handler = bnx2fc_eh_abort, /* abts */
  2451. .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
  2452. .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
  2453. .eh_host_reset_handler = fc_eh_host_reset,
  2454. .slave_alloc = fc_slave_alloc,
  2455. .change_queue_depth = scsi_change_queue_depth,
  2456. .this_id = -1,
  2457. .cmd_per_lun = 3,
  2458. .use_clustering = ENABLE_CLUSTERING,
  2459. .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
  2460. .max_sectors = 1024,
  2461. .track_queue_depth = 1,
  2462. };
  2463. static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
  2464. .frame_send = bnx2fc_xmit,
  2465. .elsct_send = bnx2fc_elsct_send,
  2466. .fcp_abort_io = bnx2fc_abort_io,
  2467. .fcp_cleanup = bnx2fc_cleanup,
  2468. .get_lesb = fcoe_get_lesb,
  2469. .rport_event_callback = bnx2fc_rport_event_handler,
  2470. };
  2471. /**
  2472. * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
  2473. * structure carrying callback function pointers
  2474. */
  2475. static struct cnic_ulp_ops bnx2fc_cnic_cb = {
  2476. .owner = THIS_MODULE,
  2477. .cnic_init = bnx2fc_ulp_init,
  2478. .cnic_exit = bnx2fc_ulp_exit,
  2479. .cnic_start = bnx2fc_ulp_start,
  2480. .cnic_stop = bnx2fc_ulp_stop,
  2481. .indicate_kcqes = bnx2fc_indicate_kcqe,
  2482. .indicate_netevent = bnx2fc_indicate_netevent,
  2483. .cnic_get_stats = bnx2fc_ulp_get_stats,
  2484. };