bnx2fc_fcoe.c 62 KB

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