bnx2fc_fcoe.c 76 KB

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