bnx2fc_fcoe.c 77 KB

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