bnx2fc_fcoe.c 76 KB

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