bnx2fc_fcoe.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454
  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. mutex_lock(&n_port->lp_mutex);
  894. list_del(&vn_port->list);
  895. mutex_unlock(&n_port->lp_mutex);
  896. queue_work(bnx2fc_wq, &port->destroy_work);
  897. return 0;
  898. }
  899. static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
  900. {
  901. struct fc_lport *lport = vport->dd_data;
  902. if (disable) {
  903. fc_vport_set_state(vport, FC_VPORT_DISABLED);
  904. fc_fabric_logoff(lport);
  905. } else {
  906. lport->boot_time = jiffies;
  907. fc_fabric_login(lport);
  908. fc_vport_setlink(lport);
  909. }
  910. return 0;
  911. }
  912. static int bnx2fc_netdev_setup(struct bnx2fc_interface *interface)
  913. {
  914. struct net_device *netdev = interface->netdev;
  915. struct net_device *physdev = interface->hba->phys_dev;
  916. struct netdev_hw_addr *ha;
  917. int sel_san_mac = 0;
  918. /* setup Source MAC Address */
  919. rcu_read_lock();
  920. for_each_dev_addr(physdev, ha) {
  921. BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
  922. ha->type);
  923. printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
  924. ha->addr[1], ha->addr[2], ha->addr[3],
  925. ha->addr[4], ha->addr[5]);
  926. if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
  927. (is_valid_ether_addr(ha->addr))) {
  928. memcpy(interface->ctlr.ctl_src_addr, ha->addr,
  929. ETH_ALEN);
  930. sel_san_mac = 1;
  931. BNX2FC_MISC_DBG("Found SAN MAC\n");
  932. }
  933. }
  934. rcu_read_unlock();
  935. if (!sel_san_mac)
  936. return -ENODEV;
  937. interface->fip_packet_type.func = bnx2fc_fip_recv;
  938. interface->fip_packet_type.type = htons(ETH_P_FIP);
  939. interface->fip_packet_type.dev = netdev;
  940. dev_add_pack(&interface->fip_packet_type);
  941. interface->fcoe_packet_type.func = bnx2fc_rcv;
  942. interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
  943. interface->fcoe_packet_type.dev = netdev;
  944. dev_add_pack(&interface->fcoe_packet_type);
  945. return 0;
  946. }
  947. static int bnx2fc_attach_transport(void)
  948. {
  949. bnx2fc_transport_template =
  950. fc_attach_transport(&bnx2fc_transport_function);
  951. if (bnx2fc_transport_template == NULL) {
  952. printk(KERN_ERR PFX "Failed to attach FC transport\n");
  953. return -ENODEV;
  954. }
  955. bnx2fc_vport_xport_template =
  956. fc_attach_transport(&bnx2fc_vport_xport_function);
  957. if (bnx2fc_vport_xport_template == NULL) {
  958. printk(KERN_ERR PFX
  959. "Failed to attach FC transport for vport\n");
  960. fc_release_transport(bnx2fc_transport_template);
  961. bnx2fc_transport_template = NULL;
  962. return -ENODEV;
  963. }
  964. return 0;
  965. }
  966. static void bnx2fc_release_transport(void)
  967. {
  968. fc_release_transport(bnx2fc_transport_template);
  969. fc_release_transport(bnx2fc_vport_xport_template);
  970. bnx2fc_transport_template = NULL;
  971. bnx2fc_vport_xport_template = NULL;
  972. }
  973. static void bnx2fc_interface_release(struct kref *kref)
  974. {
  975. struct bnx2fc_interface *interface;
  976. struct net_device *netdev;
  977. interface = container_of(kref, struct bnx2fc_interface, kref);
  978. BNX2FC_MISC_DBG("Interface is being released\n");
  979. netdev = interface->netdev;
  980. /* tear-down FIP controller */
  981. if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
  982. fcoe_ctlr_destroy(&interface->ctlr);
  983. kfree(interface);
  984. dev_put(netdev);
  985. module_put(THIS_MODULE);
  986. }
  987. static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
  988. {
  989. kref_get(&interface->kref);
  990. }
  991. static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
  992. {
  993. kref_put(&interface->kref, bnx2fc_interface_release);
  994. }
  995. static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
  996. {
  997. /* Free the command manager */
  998. if (hba->cmd_mgr) {
  999. bnx2fc_cmd_mgr_free(hba->cmd_mgr);
  1000. hba->cmd_mgr = NULL;
  1001. }
  1002. kfree(hba->tgt_ofld_list);
  1003. bnx2fc_unbind_pcidev(hba);
  1004. kfree(hba);
  1005. }
  1006. /**
  1007. * bnx2fc_hba_create - create a new bnx2fc hba
  1008. *
  1009. * @cnic: pointer to cnic device
  1010. *
  1011. * Creates a new FCoE hba on the given device.
  1012. *
  1013. */
  1014. static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
  1015. {
  1016. struct bnx2fc_hba *hba;
  1017. int rc;
  1018. hba = kzalloc(sizeof(*hba), GFP_KERNEL);
  1019. if (!hba) {
  1020. printk(KERN_ERR PFX "Unable to allocate hba structure\n");
  1021. return NULL;
  1022. }
  1023. spin_lock_init(&hba->hba_lock);
  1024. mutex_init(&hba->hba_mutex);
  1025. hba->cnic = cnic;
  1026. rc = bnx2fc_bind_pcidev(hba);
  1027. if (rc) {
  1028. printk(KERN_ERR PFX "create_adapter: bind error\n");
  1029. goto bind_err;
  1030. }
  1031. hba->phys_dev = cnic->netdev;
  1032. hba->next_conn_id = 0;
  1033. hba->tgt_ofld_list =
  1034. kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
  1035. GFP_KERNEL);
  1036. if (!hba->tgt_ofld_list) {
  1037. printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
  1038. goto tgtofld_err;
  1039. }
  1040. hba->num_ofld_sess = 0;
  1041. hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
  1042. BNX2FC_MAX_XID);
  1043. if (!hba->cmd_mgr) {
  1044. printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
  1045. goto cmgr_err;
  1046. }
  1047. init_waitqueue_head(&hba->shutdown_wait);
  1048. init_waitqueue_head(&hba->destroy_wait);
  1049. INIT_LIST_HEAD(&hba->vports);
  1050. return hba;
  1051. cmgr_err:
  1052. kfree(hba->tgt_ofld_list);
  1053. tgtofld_err:
  1054. bnx2fc_unbind_pcidev(hba);
  1055. bind_err:
  1056. kfree(hba);
  1057. return NULL;
  1058. }
  1059. struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
  1060. struct net_device *netdev,
  1061. enum fip_state fip_mode)
  1062. {
  1063. struct bnx2fc_interface *interface;
  1064. int rc = 0;
  1065. interface = kzalloc(sizeof(*interface), GFP_KERNEL);
  1066. if (!interface) {
  1067. printk(KERN_ERR PFX "Unable to allocate interface structure\n");
  1068. return NULL;
  1069. }
  1070. dev_hold(netdev);
  1071. kref_init(&interface->kref);
  1072. interface->hba = hba;
  1073. interface->netdev = netdev;
  1074. /* Initialize FIP */
  1075. fcoe_ctlr_init(&interface->ctlr, fip_mode);
  1076. interface->ctlr.send = bnx2fc_fip_send;
  1077. interface->ctlr.update_mac = bnx2fc_update_src_mac;
  1078. interface->ctlr.get_src_addr = bnx2fc_get_src_mac;
  1079. set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
  1080. rc = bnx2fc_netdev_setup(interface);
  1081. if (!rc)
  1082. return interface;
  1083. fcoe_ctlr_destroy(&interface->ctlr);
  1084. dev_put(netdev);
  1085. kfree(interface);
  1086. return NULL;
  1087. }
  1088. /**
  1089. * bnx2fc_if_create - Create FCoE instance on a given interface
  1090. *
  1091. * @interface: FCoE interface to create a local port on
  1092. * @parent: Device pointer to be the parent in sysfs for the SCSI host
  1093. * @npiv: Indicates if the port is vport or not
  1094. *
  1095. * Creates a fc_lport instance and a Scsi_Host instance and configure them.
  1096. *
  1097. * Returns: Allocated fc_lport or an error pointer
  1098. */
  1099. static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
  1100. struct device *parent, int npiv)
  1101. {
  1102. struct fc_lport *lport, *n_port;
  1103. struct fcoe_port *port;
  1104. struct Scsi_Host *shost;
  1105. struct fc_vport *vport = dev_to_vport(parent);
  1106. struct bnx2fc_lport *blport;
  1107. struct bnx2fc_hba *hba;
  1108. int rc = 0;
  1109. blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
  1110. if (!blport) {
  1111. BNX2FC_HBA_DBG(interface->ctlr.lp, "Unable to alloc blport\n");
  1112. return NULL;
  1113. }
  1114. /* Allocate Scsi_Host structure */
  1115. if (!npiv)
  1116. lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
  1117. else
  1118. lport = libfc_vport_create(vport, sizeof(*port));
  1119. if (!lport) {
  1120. printk(KERN_ERR PFX "could not allocate scsi host structure\n");
  1121. goto free_blport;
  1122. }
  1123. shost = lport->host;
  1124. port = lport_priv(lport);
  1125. port->lport = lport;
  1126. port->priv = interface;
  1127. INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
  1128. /* Configure fcoe_port */
  1129. rc = bnx2fc_lport_config(lport);
  1130. if (rc)
  1131. goto lp_config_err;
  1132. if (npiv) {
  1133. printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
  1134. vport->node_name, vport->port_name);
  1135. fc_set_wwnn(lport, vport->node_name);
  1136. fc_set_wwpn(lport, vport->port_name);
  1137. }
  1138. /* Configure netdev and networking properties of the lport */
  1139. rc = bnx2fc_net_config(lport);
  1140. if (rc) {
  1141. printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
  1142. goto lp_config_err;
  1143. }
  1144. rc = bnx2fc_shost_config(lport, parent);
  1145. if (rc) {
  1146. printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
  1147. interface->netdev->name);
  1148. goto lp_config_err;
  1149. }
  1150. /* Initialize the libfc library */
  1151. rc = bnx2fc_libfc_config(lport);
  1152. if (rc) {
  1153. printk(KERN_ERR PFX "Couldnt configure libfc\n");
  1154. goto shost_err;
  1155. }
  1156. fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
  1157. /* Allocate exchange manager */
  1158. if (!npiv)
  1159. rc = bnx2fc_em_config(lport);
  1160. else {
  1161. shost = vport_to_shost(vport);
  1162. n_port = shost_priv(shost);
  1163. rc = fc_exch_mgr_list_clone(n_port, lport);
  1164. }
  1165. if (rc) {
  1166. printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
  1167. goto shost_err;
  1168. }
  1169. bnx2fc_interface_get(interface);
  1170. hba = interface->hba;
  1171. spin_lock_bh(&hba->hba_lock);
  1172. blport->lport = lport;
  1173. list_add_tail(&blport->list, &hba->vports);
  1174. spin_unlock_bh(&hba->hba_lock);
  1175. return lport;
  1176. shost_err:
  1177. scsi_remove_host(shost);
  1178. lp_config_err:
  1179. scsi_host_put(lport->host);
  1180. free_blport:
  1181. kfree(blport);
  1182. return NULL;
  1183. }
  1184. static void bnx2fc_netdev_cleanup(struct bnx2fc_interface *interface)
  1185. {
  1186. /* Dont listen for Ethernet packets anymore */
  1187. __dev_remove_pack(&interface->fcoe_packet_type);
  1188. __dev_remove_pack(&interface->fip_packet_type);
  1189. synchronize_net();
  1190. }
  1191. static void bnx2fc_if_destroy(struct fc_lport *lport, struct bnx2fc_hba *hba)
  1192. {
  1193. struct fcoe_port *port = lport_priv(lport);
  1194. struct bnx2fc_lport *blport, *tmp;
  1195. /* Stop the transmit retry timer */
  1196. del_timer_sync(&port->timer);
  1197. /* Free existing transmit skbs */
  1198. fcoe_clean_pending_queue(lport);
  1199. /* Free queued packets for the receive thread */
  1200. bnx2fc_clean_rx_queue(lport);
  1201. /* Detach from scsi-ml */
  1202. fc_remove_host(lport->host);
  1203. scsi_remove_host(lport->host);
  1204. /*
  1205. * Note that only the physical lport will have the exchange manager.
  1206. * for vports, this function is NOP
  1207. */
  1208. fc_exch_mgr_free(lport);
  1209. /* Free memory used by statistical counters */
  1210. fc_lport_free_stats(lport);
  1211. spin_lock_bh(&hba->hba_lock);
  1212. list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
  1213. if (blport->lport == lport) {
  1214. list_del(&blport->list);
  1215. kfree(blport);
  1216. }
  1217. }
  1218. spin_unlock_bh(&hba->hba_lock);
  1219. /* Release Scsi_Host */
  1220. scsi_host_put(lport->host);
  1221. }
  1222. /**
  1223. * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
  1224. *
  1225. * @buffer: The name of the Ethernet interface to be destroyed
  1226. * @kp: The associated kernel parameter
  1227. *
  1228. * Called from sysfs.
  1229. *
  1230. * Returns: 0 for success
  1231. */
  1232. static int bnx2fc_destroy(struct net_device *netdev)
  1233. {
  1234. struct bnx2fc_interface *interface = NULL;
  1235. struct bnx2fc_hba *hba;
  1236. struct fc_lport *lport;
  1237. int rc = 0;
  1238. rtnl_lock();
  1239. mutex_lock(&bnx2fc_dev_lock);
  1240. interface = bnx2fc_interface_lookup(netdev);
  1241. if (!interface || !interface->ctlr.lp) {
  1242. rc = -ENODEV;
  1243. printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
  1244. goto netdev_err;
  1245. }
  1246. hba = interface->hba;
  1247. bnx2fc_netdev_cleanup(interface);
  1248. lport = interface->ctlr.lp;
  1249. bnx2fc_stop(interface);
  1250. list_del(&interface->list);
  1251. destroy_workqueue(interface->timer_work_queue);
  1252. bnx2fc_interface_put(interface);
  1253. bnx2fc_if_destroy(lport, hba);
  1254. netdev_err:
  1255. mutex_unlock(&bnx2fc_dev_lock);
  1256. rtnl_unlock();
  1257. return rc;
  1258. }
  1259. static void bnx2fc_destroy_work(struct work_struct *work)
  1260. {
  1261. struct fcoe_port *port;
  1262. struct fc_lport *lport;
  1263. struct bnx2fc_interface *interface;
  1264. struct bnx2fc_hba *hba;
  1265. port = container_of(work, struct fcoe_port, destroy_work);
  1266. lport = port->lport;
  1267. interface = port->priv;
  1268. hba = interface->hba;
  1269. BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
  1270. bnx2fc_port_shutdown(lport);
  1271. rtnl_lock();
  1272. mutex_lock(&bnx2fc_dev_lock);
  1273. bnx2fc_if_destroy(lport, hba);
  1274. mutex_unlock(&bnx2fc_dev_lock);
  1275. rtnl_unlock();
  1276. }
  1277. static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
  1278. {
  1279. bnx2fc_free_fw_resc(hba);
  1280. bnx2fc_free_task_ctx(hba);
  1281. }
  1282. /**
  1283. * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
  1284. * pci structure
  1285. *
  1286. * @hba: Adapter instance
  1287. */
  1288. static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
  1289. {
  1290. if (bnx2fc_setup_task_ctx(hba))
  1291. goto mem_err;
  1292. if (bnx2fc_setup_fw_resc(hba))
  1293. goto mem_err;
  1294. return 0;
  1295. mem_err:
  1296. bnx2fc_unbind_adapter_devices(hba);
  1297. return -ENOMEM;
  1298. }
  1299. static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
  1300. {
  1301. struct cnic_dev *cnic;
  1302. if (!hba->cnic) {
  1303. printk(KERN_ERR PFX "cnic is NULL\n");
  1304. return -ENODEV;
  1305. }
  1306. cnic = hba->cnic;
  1307. hba->pcidev = cnic->pcidev;
  1308. if (hba->pcidev)
  1309. pci_dev_get(hba->pcidev);
  1310. return 0;
  1311. }
  1312. static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
  1313. {
  1314. if (hba->pcidev)
  1315. pci_dev_put(hba->pcidev);
  1316. hba->pcidev = NULL;
  1317. }
  1318. /**
  1319. * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
  1320. *
  1321. * @handle: transport handle pointing to adapter struture
  1322. *
  1323. * This function maps adapter structure to pcidev structure and initiates
  1324. * firmware handshake to enable/initialize on-chip FCoE components.
  1325. * This bnx2fc - cnic interface api callback is used after following
  1326. * conditions are met -
  1327. * a) underlying network interface is up (marked by event NETDEV_UP
  1328. * from netdev
  1329. * b) bnx2fc adatper structure is registered.
  1330. */
  1331. static void bnx2fc_ulp_start(void *handle)
  1332. {
  1333. struct bnx2fc_hba *hba = handle;
  1334. struct bnx2fc_interface *interface;
  1335. struct fc_lport *lport;
  1336. mutex_lock(&bnx2fc_dev_lock);
  1337. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
  1338. bnx2fc_fw_init(hba);
  1339. BNX2FC_MISC_DBG("bnx2fc started.\n");
  1340. list_for_each_entry(interface, &if_list, list) {
  1341. if (interface->hba == hba) {
  1342. lport = interface->ctlr.lp;
  1343. /* Kick off Fabric discovery*/
  1344. printk(KERN_ERR PFX "ulp_init: start discovery\n");
  1345. lport->tt.frame_send = bnx2fc_xmit;
  1346. bnx2fc_start_disc(interface);
  1347. }
  1348. }
  1349. mutex_unlock(&bnx2fc_dev_lock);
  1350. }
  1351. static void bnx2fc_port_shutdown(struct fc_lport *lport)
  1352. {
  1353. BNX2FC_MISC_DBG("Entered %s\n", __func__);
  1354. fc_fabric_logoff(lport);
  1355. fc_lport_destroy(lport);
  1356. }
  1357. static void bnx2fc_stop(struct bnx2fc_interface *interface)
  1358. {
  1359. struct fc_lport *lport;
  1360. struct fc_lport *vport;
  1361. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
  1362. return;
  1363. lport = interface->ctlr.lp;
  1364. bnx2fc_port_shutdown(lport);
  1365. mutex_lock(&lport->lp_mutex);
  1366. list_for_each_entry(vport, &lport->vports, list)
  1367. fc_host_port_type(vport->host) =
  1368. FC_PORTTYPE_UNKNOWN;
  1369. mutex_unlock(&lport->lp_mutex);
  1370. fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
  1371. fcoe_ctlr_link_down(&interface->ctlr);
  1372. fcoe_clean_pending_queue(lport);
  1373. }
  1374. static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
  1375. {
  1376. #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
  1377. int rc = -1;
  1378. int i = HZ;
  1379. rc = bnx2fc_bind_adapter_devices(hba);
  1380. if (rc) {
  1381. printk(KERN_ALERT PFX
  1382. "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
  1383. goto err_out;
  1384. }
  1385. rc = bnx2fc_send_fw_fcoe_init_msg(hba);
  1386. if (rc) {
  1387. printk(KERN_ALERT PFX
  1388. "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
  1389. goto err_unbind;
  1390. }
  1391. /*
  1392. * Wait until the adapter init message is complete, and adapter
  1393. * state is UP.
  1394. */
  1395. while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
  1396. msleep(BNX2FC_INIT_POLL_TIME);
  1397. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
  1398. printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
  1399. "Ignoring...\n",
  1400. hba->cnic->netdev->name);
  1401. rc = -1;
  1402. goto err_unbind;
  1403. }
  1404. set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
  1405. return 0;
  1406. err_unbind:
  1407. bnx2fc_unbind_adapter_devices(hba);
  1408. err_out:
  1409. return rc;
  1410. }
  1411. static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
  1412. {
  1413. if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
  1414. if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
  1415. init_timer(&hba->destroy_timer);
  1416. hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
  1417. jiffies;
  1418. hba->destroy_timer.function = bnx2fc_destroy_timer;
  1419. hba->destroy_timer.data = (unsigned long)hba;
  1420. add_timer(&hba->destroy_timer);
  1421. wait_event_interruptible(hba->destroy_wait,
  1422. test_bit(BNX2FC_FLAG_DESTROY_CMPL,
  1423. &hba->flags));
  1424. /* This should never happen */
  1425. if (signal_pending(current))
  1426. flush_signals(current);
  1427. del_timer_sync(&hba->destroy_timer);
  1428. }
  1429. bnx2fc_unbind_adapter_devices(hba);
  1430. }
  1431. }
  1432. /**
  1433. * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
  1434. *
  1435. * @handle: transport handle pointing to adapter structure
  1436. *
  1437. * Driver checks if adapter is already in shutdown mode, if not start
  1438. * the shutdown process.
  1439. */
  1440. static void bnx2fc_ulp_stop(void *handle)
  1441. {
  1442. struct bnx2fc_hba *hba = handle;
  1443. struct bnx2fc_interface *interface;
  1444. printk(KERN_ERR "ULP_STOP\n");
  1445. mutex_lock(&bnx2fc_dev_lock);
  1446. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
  1447. goto exit;
  1448. list_for_each_entry(interface, &if_list, list) {
  1449. if (interface->hba == hba)
  1450. bnx2fc_stop(interface);
  1451. }
  1452. BUG_ON(hba->num_ofld_sess != 0);
  1453. mutex_lock(&hba->hba_mutex);
  1454. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  1455. clear_bit(ADAPTER_STATE_GOING_DOWN,
  1456. &hba->adapter_state);
  1457. clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
  1458. mutex_unlock(&hba->hba_mutex);
  1459. bnx2fc_fw_destroy(hba);
  1460. exit:
  1461. mutex_unlock(&bnx2fc_dev_lock);
  1462. }
  1463. static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
  1464. {
  1465. struct fc_lport *lport;
  1466. int wait_cnt = 0;
  1467. BNX2FC_MISC_DBG("Entered %s\n", __func__);
  1468. /* Kick off FIP/FLOGI */
  1469. if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
  1470. printk(KERN_ERR PFX "Init not done yet\n");
  1471. return;
  1472. }
  1473. lport = interface->ctlr.lp;
  1474. BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
  1475. if (!bnx2fc_link_ok(lport)) {
  1476. BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
  1477. fcoe_ctlr_link_up(&interface->ctlr);
  1478. fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
  1479. set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
  1480. }
  1481. /* wait for the FCF to be selected before issuing FLOGI */
  1482. while (!interface->ctlr.sel_fcf) {
  1483. msleep(250);
  1484. /* give up after 3 secs */
  1485. if (++wait_cnt > 12)
  1486. break;
  1487. }
  1488. fc_lport_init(lport);
  1489. fc_fabric_login(lport);
  1490. }
  1491. /**
  1492. * bnx2fc_ulp_init - Initialize an adapter instance
  1493. *
  1494. * @dev : cnic device handle
  1495. * Called from cnic_register_driver() context to initialize all
  1496. * enumerated cnic devices. This routine allocates adapter structure
  1497. * and other device specific resources.
  1498. */
  1499. static void bnx2fc_ulp_init(struct cnic_dev *dev)
  1500. {
  1501. struct bnx2fc_hba *hba;
  1502. int rc = 0;
  1503. BNX2FC_MISC_DBG("Entered %s\n", __func__);
  1504. /* bnx2fc works only when bnx2x is loaded */
  1505. if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
  1506. (dev->max_fcoe_conn == 0)) {
  1507. printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
  1508. " flags: %lx fcoe_conn: %d\n",
  1509. dev->netdev->name, dev->flags, dev->max_fcoe_conn);
  1510. return;
  1511. }
  1512. hba = bnx2fc_hba_create(dev);
  1513. if (!hba) {
  1514. printk(KERN_ERR PFX "hba initialization failed\n");
  1515. return;
  1516. }
  1517. /* Add HBA to the adapter list */
  1518. mutex_lock(&bnx2fc_dev_lock);
  1519. list_add_tail(&hba->list, &adapter_list);
  1520. adapter_count++;
  1521. mutex_unlock(&bnx2fc_dev_lock);
  1522. clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
  1523. rc = dev->register_device(dev, CNIC_ULP_FCOE,
  1524. (void *) hba);
  1525. if (rc)
  1526. printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
  1527. else
  1528. set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
  1529. }
  1530. static int bnx2fc_disable(struct net_device *netdev)
  1531. {
  1532. struct bnx2fc_interface *interface;
  1533. int rc = 0;
  1534. rtnl_lock();
  1535. mutex_lock(&bnx2fc_dev_lock);
  1536. interface = bnx2fc_interface_lookup(netdev);
  1537. if (!interface || !interface->ctlr.lp) {
  1538. rc = -ENODEV;
  1539. printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
  1540. } else {
  1541. fcoe_ctlr_link_down(&interface->ctlr);
  1542. fcoe_clean_pending_queue(interface->ctlr.lp);
  1543. }
  1544. mutex_unlock(&bnx2fc_dev_lock);
  1545. rtnl_unlock();
  1546. return rc;
  1547. }
  1548. static int bnx2fc_enable(struct net_device *netdev)
  1549. {
  1550. struct bnx2fc_interface *interface;
  1551. int rc = 0;
  1552. rtnl_lock();
  1553. mutex_lock(&bnx2fc_dev_lock);
  1554. interface = bnx2fc_interface_lookup(netdev);
  1555. if (!interface || !interface->ctlr.lp) {
  1556. rc = -ENODEV;
  1557. printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
  1558. } else if (!bnx2fc_link_ok(interface->ctlr.lp))
  1559. fcoe_ctlr_link_up(&interface->ctlr);
  1560. mutex_unlock(&bnx2fc_dev_lock);
  1561. rtnl_unlock();
  1562. return rc;
  1563. }
  1564. /**
  1565. * bnx2fc_create - Create bnx2fc FCoE interface
  1566. *
  1567. * @buffer: The name of Ethernet interface to create on
  1568. * @kp: The associated kernel param
  1569. *
  1570. * Called from sysfs.
  1571. *
  1572. * Returns: 0 for success
  1573. */
  1574. static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
  1575. {
  1576. struct bnx2fc_interface *interface;
  1577. struct bnx2fc_hba *hba;
  1578. struct net_device *phys_dev;
  1579. struct fc_lport *lport;
  1580. struct ethtool_drvinfo drvinfo;
  1581. int rc = 0;
  1582. int vlan_id;
  1583. BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
  1584. if (fip_mode != FIP_MODE_FABRIC) {
  1585. printk(KERN_ERR "fip mode not FABRIC\n");
  1586. return -EIO;
  1587. }
  1588. rtnl_lock();
  1589. mutex_lock(&bnx2fc_dev_lock);
  1590. if (!try_module_get(THIS_MODULE)) {
  1591. rc = -EINVAL;
  1592. goto mod_err;
  1593. }
  1594. /* obtain physical netdev */
  1595. if (netdev->priv_flags & IFF_802_1Q_VLAN) {
  1596. phys_dev = vlan_dev_real_dev(netdev);
  1597. vlan_id = vlan_dev_vlan_id(netdev);
  1598. } else {
  1599. printk(KERN_ERR PFX "Not a vlan device\n");
  1600. rc = -EINVAL;
  1601. goto netdev_err;
  1602. }
  1603. /* verify if the physical device is a netxtreme2 device */
  1604. if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
  1605. memset(&drvinfo, 0, sizeof(drvinfo));
  1606. phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
  1607. if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
  1608. printk(KERN_ERR PFX "Not a netxtreme2 device\n");
  1609. rc = -EINVAL;
  1610. goto netdev_err;
  1611. }
  1612. } else {
  1613. printk(KERN_ERR PFX "unable to obtain drv_info\n");
  1614. rc = -EINVAL;
  1615. goto netdev_err;
  1616. }
  1617. /* obtain interface and initialize rest of the structure */
  1618. hba = bnx2fc_hba_lookup(phys_dev);
  1619. if (!hba) {
  1620. rc = -ENODEV;
  1621. printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
  1622. goto netdev_err;
  1623. }
  1624. if (bnx2fc_interface_lookup(netdev)) {
  1625. rc = -EEXIST;
  1626. goto netdev_err;
  1627. }
  1628. interface = bnx2fc_interface_create(hba, netdev, fip_mode);
  1629. if (!interface) {
  1630. printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
  1631. goto ifput_err;
  1632. }
  1633. interface->vlan_id = vlan_id;
  1634. interface->vlan_enabled = 1;
  1635. interface->timer_work_queue =
  1636. create_singlethread_workqueue("bnx2fc_timer_wq");
  1637. if (!interface->timer_work_queue) {
  1638. printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
  1639. rc = -EINVAL;
  1640. goto ifput_err;
  1641. }
  1642. lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
  1643. if (!lport) {
  1644. printk(KERN_ERR PFX "Failed to create interface (%s)\n",
  1645. netdev->name);
  1646. bnx2fc_netdev_cleanup(interface);
  1647. rc = -EINVAL;
  1648. goto if_create_err;
  1649. }
  1650. /* Add interface to if_list */
  1651. list_add_tail(&interface->list, &if_list);
  1652. lport->boot_time = jiffies;
  1653. /* Make this master N_port */
  1654. interface->ctlr.lp = lport;
  1655. BNX2FC_HBA_DBG(lport, "create: START DISC\n");
  1656. bnx2fc_start_disc(interface);
  1657. /*
  1658. * Release from kref_init in bnx2fc_interface_setup, on success
  1659. * lport should be holding a reference taken in bnx2fc_if_create
  1660. */
  1661. bnx2fc_interface_put(interface);
  1662. /* put netdev that was held while calling dev_get_by_name */
  1663. mutex_unlock(&bnx2fc_dev_lock);
  1664. rtnl_unlock();
  1665. return 0;
  1666. if_create_err:
  1667. destroy_workqueue(interface->timer_work_queue);
  1668. ifput_err:
  1669. bnx2fc_interface_put(interface);
  1670. netdev_err:
  1671. module_put(THIS_MODULE);
  1672. mod_err:
  1673. mutex_unlock(&bnx2fc_dev_lock);
  1674. rtnl_unlock();
  1675. return rc;
  1676. }
  1677. /**
  1678. * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
  1679. *
  1680. * @cnic: Pointer to cnic device instance
  1681. *
  1682. **/
  1683. static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
  1684. {
  1685. struct list_head *list;
  1686. struct list_head *temp;
  1687. struct bnx2fc_hba *hba;
  1688. /* Called with bnx2fc_dev_lock held */
  1689. list_for_each_safe(list, temp, &adapter_list) {
  1690. hba = (struct bnx2fc_hba *)list;
  1691. if (hba->cnic == cnic)
  1692. return hba;
  1693. }
  1694. return NULL;
  1695. }
  1696. static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
  1697. *netdev)
  1698. {
  1699. struct bnx2fc_interface *interface;
  1700. /* Called with bnx2fc_dev_lock held */
  1701. list_for_each_entry(interface, &if_list, list) {
  1702. if (interface->netdev == netdev)
  1703. return interface;
  1704. }
  1705. return NULL;
  1706. }
  1707. static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
  1708. *phys_dev)
  1709. {
  1710. struct bnx2fc_hba *hba;
  1711. /* Called with bnx2fc_dev_lock held */
  1712. list_for_each_entry(hba, &adapter_list, list) {
  1713. if (hba->phys_dev == phys_dev)
  1714. return hba;
  1715. }
  1716. printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
  1717. return NULL;
  1718. }
  1719. /**
  1720. * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
  1721. *
  1722. * @dev cnic device handle
  1723. */
  1724. static void bnx2fc_ulp_exit(struct cnic_dev *dev)
  1725. {
  1726. struct bnx2fc_hba *hba;
  1727. struct bnx2fc_interface *interface, *tmp;
  1728. struct fc_lport *lport;
  1729. BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
  1730. if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
  1731. printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
  1732. dev->netdev->name, dev->flags);
  1733. return;
  1734. }
  1735. mutex_lock(&bnx2fc_dev_lock);
  1736. hba = bnx2fc_find_hba_for_cnic(dev);
  1737. if (!hba) {
  1738. printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
  1739. dev);
  1740. mutex_unlock(&bnx2fc_dev_lock);
  1741. return;
  1742. }
  1743. list_del_init(&hba->list);
  1744. adapter_count--;
  1745. list_for_each_entry_safe(interface, tmp, &if_list, list) {
  1746. /* destroy not called yet, move to quiesced list */
  1747. if (interface->hba == hba) {
  1748. bnx2fc_netdev_cleanup(interface);
  1749. bnx2fc_stop(interface);
  1750. list_del(&interface->list);
  1751. lport = interface->ctlr.lp;
  1752. bnx2fc_interface_put(interface);
  1753. bnx2fc_if_destroy(lport, hba);
  1754. }
  1755. }
  1756. mutex_unlock(&bnx2fc_dev_lock);
  1757. bnx2fc_ulp_stop(hba);
  1758. /* unregister cnic device */
  1759. if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
  1760. hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
  1761. bnx2fc_hba_destroy(hba);
  1762. }
  1763. /**
  1764. * bnx2fc_fcoe_reset - Resets the fcoe
  1765. *
  1766. * @shost: shost the reset is from
  1767. *
  1768. * Returns: always 0
  1769. */
  1770. static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
  1771. {
  1772. struct fc_lport *lport = shost_priv(shost);
  1773. fc_lport_reset(lport);
  1774. return 0;
  1775. }
  1776. static bool bnx2fc_match(struct net_device *netdev)
  1777. {
  1778. mutex_lock(&bnx2fc_dev_lock);
  1779. if (netdev->priv_flags & IFF_802_1Q_VLAN) {
  1780. struct net_device *phys_dev = vlan_dev_real_dev(netdev);
  1781. if (bnx2fc_hba_lookup(phys_dev)) {
  1782. mutex_unlock(&bnx2fc_dev_lock);
  1783. return true;
  1784. }
  1785. }
  1786. mutex_unlock(&bnx2fc_dev_lock);
  1787. return false;
  1788. }
  1789. static struct fcoe_transport bnx2fc_transport = {
  1790. .name = {"bnx2fc"},
  1791. .attached = false,
  1792. .list = LIST_HEAD_INIT(bnx2fc_transport.list),
  1793. .match = bnx2fc_match,
  1794. .create = bnx2fc_create,
  1795. .destroy = bnx2fc_destroy,
  1796. .enable = bnx2fc_enable,
  1797. .disable = bnx2fc_disable,
  1798. };
  1799. /**
  1800. * bnx2fc_percpu_thread_create - Create a receive thread for an
  1801. * online CPU
  1802. *
  1803. * @cpu: cpu index for the online cpu
  1804. */
  1805. static void bnx2fc_percpu_thread_create(unsigned int cpu)
  1806. {
  1807. struct bnx2fc_percpu_s *p;
  1808. struct task_struct *thread;
  1809. p = &per_cpu(bnx2fc_percpu, cpu);
  1810. thread = kthread_create(bnx2fc_percpu_io_thread,
  1811. (void *)p,
  1812. "bnx2fc_thread/%d", cpu);
  1813. /* bind thread to the cpu */
  1814. if (likely(!IS_ERR(p->iothread))) {
  1815. kthread_bind(thread, cpu);
  1816. p->iothread = thread;
  1817. wake_up_process(thread);
  1818. }
  1819. }
  1820. static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
  1821. {
  1822. struct bnx2fc_percpu_s *p;
  1823. struct task_struct *thread;
  1824. struct bnx2fc_work *work, *tmp;
  1825. LIST_HEAD(work_list);
  1826. BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
  1827. /* Prevent any new work from being queued for this CPU */
  1828. p = &per_cpu(bnx2fc_percpu, cpu);
  1829. spin_lock_bh(&p->fp_work_lock);
  1830. thread = p->iothread;
  1831. p->iothread = NULL;
  1832. /* Free all work in the list */
  1833. list_for_each_entry_safe(work, tmp, &work_list, list) {
  1834. list_del_init(&work->list);
  1835. bnx2fc_process_cq_compl(work->tgt, work->wqe);
  1836. kfree(work);
  1837. }
  1838. spin_unlock_bh(&p->fp_work_lock);
  1839. if (thread)
  1840. kthread_stop(thread);
  1841. }
  1842. /**
  1843. * bnx2fc_cpu_callback - Handler for CPU hotplug events
  1844. *
  1845. * @nfb: The callback data block
  1846. * @action: The event triggering the callback
  1847. * @hcpu: The index of the CPU that the event is for
  1848. *
  1849. * This creates or destroys per-CPU data for fcoe
  1850. *
  1851. * Returns NOTIFY_OK always.
  1852. */
  1853. static int bnx2fc_cpu_callback(struct notifier_block *nfb,
  1854. unsigned long action, void *hcpu)
  1855. {
  1856. unsigned cpu = (unsigned long)hcpu;
  1857. switch (action) {
  1858. case CPU_ONLINE:
  1859. case CPU_ONLINE_FROZEN:
  1860. printk(PFX "CPU %x online: Create Rx thread\n", cpu);
  1861. bnx2fc_percpu_thread_create(cpu);
  1862. break;
  1863. case CPU_DEAD:
  1864. case CPU_DEAD_FROZEN:
  1865. printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
  1866. bnx2fc_percpu_thread_destroy(cpu);
  1867. break;
  1868. default:
  1869. break;
  1870. }
  1871. return NOTIFY_OK;
  1872. }
  1873. /**
  1874. * bnx2fc_mod_init - module init entry point
  1875. *
  1876. * Initialize driver wide global data structures, and register
  1877. * with cnic module
  1878. **/
  1879. static int __init bnx2fc_mod_init(void)
  1880. {
  1881. struct fcoe_percpu_s *bg;
  1882. struct task_struct *l2_thread;
  1883. int rc = 0;
  1884. unsigned int cpu = 0;
  1885. struct bnx2fc_percpu_s *p;
  1886. printk(KERN_INFO PFX "%s", version);
  1887. /* register as a fcoe transport */
  1888. rc = fcoe_transport_attach(&bnx2fc_transport);
  1889. if (rc) {
  1890. printk(KERN_ERR "failed to register an fcoe transport, check "
  1891. "if libfcoe is loaded\n");
  1892. goto out;
  1893. }
  1894. INIT_LIST_HEAD(&adapter_list);
  1895. INIT_LIST_HEAD(&if_list);
  1896. mutex_init(&bnx2fc_dev_lock);
  1897. adapter_count = 0;
  1898. /* Attach FC transport template */
  1899. rc = bnx2fc_attach_transport();
  1900. if (rc)
  1901. goto detach_ft;
  1902. bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
  1903. if (!bnx2fc_wq) {
  1904. rc = -ENOMEM;
  1905. goto release_bt;
  1906. }
  1907. bg = &bnx2fc_global;
  1908. skb_queue_head_init(&bg->fcoe_rx_list);
  1909. l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
  1910. (void *)bg,
  1911. "bnx2fc_l2_thread");
  1912. if (IS_ERR(l2_thread)) {
  1913. rc = PTR_ERR(l2_thread);
  1914. goto free_wq;
  1915. }
  1916. wake_up_process(l2_thread);
  1917. spin_lock_bh(&bg->fcoe_rx_list.lock);
  1918. bg->thread = l2_thread;
  1919. spin_unlock_bh(&bg->fcoe_rx_list.lock);
  1920. for_each_possible_cpu(cpu) {
  1921. p = &per_cpu(bnx2fc_percpu, cpu);
  1922. INIT_LIST_HEAD(&p->work_list);
  1923. spin_lock_init(&p->fp_work_lock);
  1924. }
  1925. for_each_online_cpu(cpu) {
  1926. bnx2fc_percpu_thread_create(cpu);
  1927. }
  1928. /* Initialize per CPU interrupt thread */
  1929. register_hotcpu_notifier(&bnx2fc_cpu_notifier);
  1930. cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
  1931. return 0;
  1932. free_wq:
  1933. destroy_workqueue(bnx2fc_wq);
  1934. release_bt:
  1935. bnx2fc_release_transport();
  1936. detach_ft:
  1937. fcoe_transport_detach(&bnx2fc_transport);
  1938. out:
  1939. return rc;
  1940. }
  1941. static void __exit bnx2fc_mod_exit(void)
  1942. {
  1943. LIST_HEAD(to_be_deleted);
  1944. struct bnx2fc_hba *hba, *next;
  1945. struct fcoe_percpu_s *bg;
  1946. struct task_struct *l2_thread;
  1947. struct sk_buff *skb;
  1948. unsigned int cpu = 0;
  1949. /*
  1950. * NOTE: Since cnic calls register_driver routine rtnl_lock,
  1951. * it will have higher precedence than bnx2fc_dev_lock.
  1952. * unregister_device() cannot be called with bnx2fc_dev_lock
  1953. * held.
  1954. */
  1955. mutex_lock(&bnx2fc_dev_lock);
  1956. list_splice(&adapter_list, &to_be_deleted);
  1957. INIT_LIST_HEAD(&adapter_list);
  1958. adapter_count = 0;
  1959. mutex_unlock(&bnx2fc_dev_lock);
  1960. /* Unregister with cnic */
  1961. list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
  1962. list_del_init(&hba->list);
  1963. printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
  1964. hba);
  1965. bnx2fc_ulp_stop(hba);
  1966. /* unregister cnic device */
  1967. if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
  1968. &hba->reg_with_cnic))
  1969. hba->cnic->unregister_device(hba->cnic,
  1970. CNIC_ULP_FCOE);
  1971. bnx2fc_hba_destroy(hba);
  1972. }
  1973. cnic_unregister_driver(CNIC_ULP_FCOE);
  1974. /* Destroy global thread */
  1975. bg = &bnx2fc_global;
  1976. spin_lock_bh(&bg->fcoe_rx_list.lock);
  1977. l2_thread = bg->thread;
  1978. bg->thread = NULL;
  1979. while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
  1980. kfree_skb(skb);
  1981. spin_unlock_bh(&bg->fcoe_rx_list.lock);
  1982. if (l2_thread)
  1983. kthread_stop(l2_thread);
  1984. unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
  1985. /* Destroy per cpu threads */
  1986. for_each_online_cpu(cpu) {
  1987. bnx2fc_percpu_thread_destroy(cpu);
  1988. }
  1989. destroy_workqueue(bnx2fc_wq);
  1990. /*
  1991. * detach from scsi transport
  1992. * must happen after all destroys are done
  1993. */
  1994. bnx2fc_release_transport();
  1995. /* detach from fcoe transport */
  1996. fcoe_transport_detach(&bnx2fc_transport);
  1997. }
  1998. module_init(bnx2fc_mod_init);
  1999. module_exit(bnx2fc_mod_exit);
  2000. static struct fc_function_template bnx2fc_transport_function = {
  2001. .show_host_node_name = 1,
  2002. .show_host_port_name = 1,
  2003. .show_host_supported_classes = 1,
  2004. .show_host_supported_fc4s = 1,
  2005. .show_host_active_fc4s = 1,
  2006. .show_host_maxframe_size = 1,
  2007. .show_host_port_id = 1,
  2008. .show_host_supported_speeds = 1,
  2009. .get_host_speed = fc_get_host_speed,
  2010. .show_host_speed = 1,
  2011. .show_host_port_type = 1,
  2012. .get_host_port_state = fc_get_host_port_state,
  2013. .show_host_port_state = 1,
  2014. .show_host_symbolic_name = 1,
  2015. .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
  2016. sizeof(struct bnx2fc_rport)),
  2017. .show_rport_maxframe_size = 1,
  2018. .show_rport_supported_classes = 1,
  2019. .show_host_fabric_name = 1,
  2020. .show_starget_node_name = 1,
  2021. .show_starget_port_name = 1,
  2022. .show_starget_port_id = 1,
  2023. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  2024. .show_rport_dev_loss_tmo = 1,
  2025. .get_fc_host_stats = bnx2fc_get_host_stats,
  2026. .issue_fc_host_lip = bnx2fc_fcoe_reset,
  2027. .terminate_rport_io = fc_rport_terminate_io,
  2028. .vport_create = bnx2fc_vport_create,
  2029. .vport_delete = bnx2fc_vport_destroy,
  2030. .vport_disable = bnx2fc_vport_disable,
  2031. };
  2032. static struct fc_function_template bnx2fc_vport_xport_function = {
  2033. .show_host_node_name = 1,
  2034. .show_host_port_name = 1,
  2035. .show_host_supported_classes = 1,
  2036. .show_host_supported_fc4s = 1,
  2037. .show_host_active_fc4s = 1,
  2038. .show_host_maxframe_size = 1,
  2039. .show_host_port_id = 1,
  2040. .show_host_supported_speeds = 1,
  2041. .get_host_speed = fc_get_host_speed,
  2042. .show_host_speed = 1,
  2043. .show_host_port_type = 1,
  2044. .get_host_port_state = fc_get_host_port_state,
  2045. .show_host_port_state = 1,
  2046. .show_host_symbolic_name = 1,
  2047. .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
  2048. sizeof(struct bnx2fc_rport)),
  2049. .show_rport_maxframe_size = 1,
  2050. .show_rport_supported_classes = 1,
  2051. .show_host_fabric_name = 1,
  2052. .show_starget_node_name = 1,
  2053. .show_starget_port_name = 1,
  2054. .show_starget_port_id = 1,
  2055. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  2056. .show_rport_dev_loss_tmo = 1,
  2057. .get_fc_host_stats = fc_get_host_stats,
  2058. .issue_fc_host_lip = bnx2fc_fcoe_reset,
  2059. .terminate_rport_io = fc_rport_terminate_io,
  2060. };
  2061. /**
  2062. * scsi_host_template structure used while registering with SCSI-ml
  2063. */
  2064. static struct scsi_host_template bnx2fc_shost_template = {
  2065. .module = THIS_MODULE,
  2066. .name = "Broadcom Offload FCoE Initiator",
  2067. .queuecommand = bnx2fc_queuecommand,
  2068. .eh_abort_handler = bnx2fc_eh_abort, /* abts */
  2069. .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
  2070. .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
  2071. .eh_host_reset_handler = fc_eh_host_reset,
  2072. .slave_alloc = fc_slave_alloc,
  2073. .change_queue_depth = fc_change_queue_depth,
  2074. .change_queue_type = fc_change_queue_type,
  2075. .this_id = -1,
  2076. .cmd_per_lun = 3,
  2077. .can_queue = BNX2FC_CAN_QUEUE,
  2078. .use_clustering = ENABLE_CLUSTERING,
  2079. .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
  2080. .max_sectors = 512,
  2081. };
  2082. static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
  2083. .frame_send = bnx2fc_xmit,
  2084. .elsct_send = bnx2fc_elsct_send,
  2085. .fcp_abort_io = bnx2fc_abort_io,
  2086. .fcp_cleanup = bnx2fc_cleanup,
  2087. .rport_event_callback = bnx2fc_rport_event_handler,
  2088. };
  2089. /**
  2090. * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
  2091. * structure carrying callback function pointers
  2092. */
  2093. static struct cnic_ulp_ops bnx2fc_cnic_cb = {
  2094. .owner = THIS_MODULE,
  2095. .cnic_init = bnx2fc_ulp_init,
  2096. .cnic_exit = bnx2fc_ulp_exit,
  2097. .cnic_start = bnx2fc_ulp_start,
  2098. .cnic_stop = bnx2fc_ulp_stop,
  2099. .indicate_kcqes = bnx2fc_indicate_kcqe,
  2100. .indicate_netevent = bnx2fc_indicate_netevent,
  2101. };