fcoe.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955
  1. /*
  2. * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * Maintained at www.Open-FCoE.org
  18. */
  19. #include <linux/module.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/etherdevice.h>
  23. #include <linux/ethtool.h>
  24. #include <linux/if_ether.h>
  25. #include <linux/if_vlan.h>
  26. #include <linux/crc32.h>
  27. #include <linux/slab.h>
  28. #include <linux/cpu.h>
  29. #include <linux/fs.h>
  30. #include <linux/sysfs.h>
  31. #include <linux/ctype.h>
  32. #include <linux/workqueue.h>
  33. #include <net/dcbnl.h>
  34. #include <net/dcbevent.h>
  35. #include <scsi/scsi_tcq.h>
  36. #include <scsi/scsicam.h>
  37. #include <scsi/scsi_transport.h>
  38. #include <scsi/scsi_transport_fc.h>
  39. #include <net/rtnetlink.h>
  40. #include <scsi/fc/fc_encaps.h>
  41. #include <scsi/fc/fc_fip.h>
  42. #include <scsi/fc/fc_fcoe.h>
  43. #include <scsi/libfc.h>
  44. #include <scsi/fc_frame.h>
  45. #include <scsi/libfcoe.h>
  46. #include "fcoe.h"
  47. MODULE_AUTHOR("Open-FCoE.org");
  48. MODULE_DESCRIPTION("FCoE");
  49. MODULE_LICENSE("GPL v2");
  50. /* Performance tuning parameters for fcoe */
  51. static unsigned int fcoe_ddp_min = 4096;
  52. module_param_named(ddp_min, fcoe_ddp_min, uint, S_IRUGO | S_IWUSR);
  53. MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for " \
  54. "Direct Data Placement (DDP).");
  55. unsigned int fcoe_debug_logging;
  56. module_param_named(debug_logging, fcoe_debug_logging, int, S_IRUGO|S_IWUSR);
  57. MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
  58. static DEFINE_MUTEX(fcoe_config_mutex);
  59. static struct workqueue_struct *fcoe_wq;
  60. /* fcoe_percpu_clean completion. Waiter protected by fcoe_create_mutex */
  61. static DECLARE_COMPLETION(fcoe_flush_completion);
  62. /* fcoe host list */
  63. /* must only by accessed under the RTNL mutex */
  64. static LIST_HEAD(fcoe_hostlist);
  65. static DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
  66. /* Function Prototypes */
  67. static int fcoe_reset(struct Scsi_Host *);
  68. static int fcoe_xmit(struct fc_lport *, struct fc_frame *);
  69. static int fcoe_rcv(struct sk_buff *, struct net_device *,
  70. struct packet_type *, struct net_device *);
  71. static int fcoe_percpu_receive_thread(void *);
  72. static void fcoe_percpu_clean(struct fc_lport *);
  73. static int fcoe_link_ok(struct fc_lport *);
  74. static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
  75. static int fcoe_hostlist_add(const struct fc_lport *);
  76. static void fcoe_hostlist_del(const struct fc_lport *);
  77. static int fcoe_device_notification(struct notifier_block *, ulong, void *);
  78. static void fcoe_dev_setup(void);
  79. static void fcoe_dev_cleanup(void);
  80. static struct fcoe_interface
  81. *fcoe_hostlist_lookup_port(const struct net_device *);
  82. static int fcoe_fip_recv(struct sk_buff *, struct net_device *,
  83. struct packet_type *, struct net_device *);
  84. static void fcoe_fip_send(struct fcoe_ctlr *, struct sk_buff *);
  85. static void fcoe_update_src_mac(struct fc_lport *, u8 *);
  86. static u8 *fcoe_get_src_mac(struct fc_lport *);
  87. static void fcoe_destroy_work(struct work_struct *);
  88. static int fcoe_ddp_setup(struct fc_lport *, u16, struct scatterlist *,
  89. unsigned int);
  90. static int fcoe_ddp_done(struct fc_lport *, u16);
  91. static int fcoe_ddp_target(struct fc_lport *, u16, struct scatterlist *,
  92. unsigned int);
  93. static int fcoe_cpu_callback(struct notifier_block *, unsigned long, void *);
  94. static int fcoe_dcb_app_notification(struct notifier_block *notifier,
  95. ulong event, void *ptr);
  96. static bool fcoe_match(struct net_device *netdev);
  97. static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode);
  98. static int fcoe_destroy(struct net_device *netdev);
  99. static int fcoe_enable(struct net_device *netdev);
  100. static int fcoe_disable(struct net_device *netdev);
  101. /* fcoe_syfs control interface handlers */
  102. static int fcoe_ctlr_alloc(struct net_device *netdev);
  103. static int fcoe_ctlr_enabled(struct fcoe_ctlr_device *cdev);
  104. static struct fc_seq *fcoe_elsct_send(struct fc_lport *,
  105. u32 did, struct fc_frame *,
  106. unsigned int op,
  107. void (*resp)(struct fc_seq *,
  108. struct fc_frame *,
  109. void *),
  110. void *, u32 timeout);
  111. static void fcoe_recv_frame(struct sk_buff *skb);
  112. /* notification function for packets from net device */
  113. static struct notifier_block fcoe_notifier = {
  114. .notifier_call = fcoe_device_notification,
  115. };
  116. /* notification function for CPU hotplug events */
  117. static struct notifier_block fcoe_cpu_notifier = {
  118. .notifier_call = fcoe_cpu_callback,
  119. };
  120. /* notification function for DCB events */
  121. static struct notifier_block dcb_notifier = {
  122. .notifier_call = fcoe_dcb_app_notification,
  123. };
  124. static struct scsi_transport_template *fcoe_nport_scsi_transport;
  125. static struct scsi_transport_template *fcoe_vport_scsi_transport;
  126. static int fcoe_vport_destroy(struct fc_vport *);
  127. static int fcoe_vport_create(struct fc_vport *, bool disabled);
  128. static int fcoe_vport_disable(struct fc_vport *, bool disable);
  129. static void fcoe_set_vport_symbolic_name(struct fc_vport *);
  130. static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *);
  131. static void fcoe_fcf_get_vlan_id(struct fcoe_fcf_device *);
  132. static struct fcoe_sysfs_function_template fcoe_sysfs_templ = {
  133. .set_fcoe_ctlr_mode = fcoe_ctlr_set_fip_mode,
  134. .set_fcoe_ctlr_enabled = fcoe_ctlr_enabled,
  135. .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
  136. .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
  137. .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
  138. .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
  139. .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
  140. .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
  141. .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
  142. .get_fcoe_fcf_vlan_id = fcoe_fcf_get_vlan_id,
  143. };
  144. static struct libfc_function_template fcoe_libfc_fcn_templ = {
  145. .frame_send = fcoe_xmit,
  146. .ddp_setup = fcoe_ddp_setup,
  147. .ddp_done = fcoe_ddp_done,
  148. .ddp_target = fcoe_ddp_target,
  149. .elsct_send = fcoe_elsct_send,
  150. .get_lesb = fcoe_get_lesb,
  151. .lport_set_port_id = fcoe_set_port_id,
  152. };
  153. static struct fc_function_template fcoe_nport_fc_functions = {
  154. .show_host_node_name = 1,
  155. .show_host_port_name = 1,
  156. .show_host_supported_classes = 1,
  157. .show_host_supported_fc4s = 1,
  158. .show_host_active_fc4s = 1,
  159. .show_host_maxframe_size = 1,
  160. .show_host_serial_number = 1,
  161. .show_host_manufacturer = 1,
  162. .show_host_model = 1,
  163. .show_host_model_description = 1,
  164. .show_host_hardware_version = 1,
  165. .show_host_driver_version = 1,
  166. .show_host_firmware_version = 1,
  167. .show_host_optionrom_version = 1,
  168. .show_host_port_id = 1,
  169. .show_host_supported_speeds = 1,
  170. .get_host_speed = fc_get_host_speed,
  171. .show_host_speed = 1,
  172. .show_host_port_type = 1,
  173. .get_host_port_state = fc_get_host_port_state,
  174. .show_host_port_state = 1,
  175. .show_host_symbolic_name = 1,
  176. .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
  177. .show_rport_maxframe_size = 1,
  178. .show_rport_supported_classes = 1,
  179. .show_host_fabric_name = 1,
  180. .show_starget_node_name = 1,
  181. .show_starget_port_name = 1,
  182. .show_starget_port_id = 1,
  183. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  184. .show_rport_dev_loss_tmo = 1,
  185. .get_fc_host_stats = fc_get_host_stats,
  186. .issue_fc_host_lip = fcoe_reset,
  187. .terminate_rport_io = fc_rport_terminate_io,
  188. .vport_create = fcoe_vport_create,
  189. .vport_delete = fcoe_vport_destroy,
  190. .vport_disable = fcoe_vport_disable,
  191. .set_vport_symbolic_name = fcoe_set_vport_symbolic_name,
  192. .bsg_request = fc_lport_bsg_request,
  193. };
  194. static struct fc_function_template fcoe_vport_fc_functions = {
  195. .show_host_node_name = 1,
  196. .show_host_port_name = 1,
  197. .show_host_supported_classes = 1,
  198. .show_host_supported_fc4s = 1,
  199. .show_host_active_fc4s = 1,
  200. .show_host_maxframe_size = 1,
  201. .show_host_serial_number = 1,
  202. .show_host_manufacturer = 1,
  203. .show_host_model = 1,
  204. .show_host_model_description = 1,
  205. .show_host_hardware_version = 1,
  206. .show_host_driver_version = 1,
  207. .show_host_firmware_version = 1,
  208. .show_host_optionrom_version = 1,
  209. .show_host_port_id = 1,
  210. .show_host_supported_speeds = 1,
  211. .get_host_speed = fc_get_host_speed,
  212. .show_host_speed = 1,
  213. .show_host_port_type = 1,
  214. .get_host_port_state = fc_get_host_port_state,
  215. .show_host_port_state = 1,
  216. .show_host_symbolic_name = 1,
  217. .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
  218. .show_rport_maxframe_size = 1,
  219. .show_rport_supported_classes = 1,
  220. .show_host_fabric_name = 1,
  221. .show_starget_node_name = 1,
  222. .show_starget_port_name = 1,
  223. .show_starget_port_id = 1,
  224. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  225. .show_rport_dev_loss_tmo = 1,
  226. .get_fc_host_stats = fc_get_host_stats,
  227. .issue_fc_host_lip = fcoe_reset,
  228. .terminate_rport_io = fc_rport_terminate_io,
  229. .bsg_request = fc_lport_bsg_request,
  230. };
  231. static struct scsi_host_template fcoe_shost_template = {
  232. .module = THIS_MODULE,
  233. .name = "FCoE Driver",
  234. .proc_name = FCOE_NAME,
  235. .queuecommand = fc_queuecommand,
  236. .eh_abort_handler = fc_eh_abort,
  237. .eh_device_reset_handler = fc_eh_device_reset,
  238. .eh_host_reset_handler = fc_eh_host_reset,
  239. .slave_alloc = fc_slave_alloc,
  240. .change_queue_depth = fc_change_queue_depth,
  241. .change_queue_type = fc_change_queue_type,
  242. .this_id = -1,
  243. .cmd_per_lun = 3,
  244. .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
  245. .use_clustering = ENABLE_CLUSTERING,
  246. .sg_tablesize = SG_ALL,
  247. .max_sectors = 0xffff,
  248. };
  249. /**
  250. * fcoe_interface_setup() - Setup a FCoE interface
  251. * @fcoe: The new FCoE interface
  252. * @netdev: The net device that the fcoe interface is on
  253. *
  254. * Returns : 0 for success
  255. * Locking: must be called with the RTNL mutex held
  256. */
  257. static int fcoe_interface_setup(struct fcoe_interface *fcoe,
  258. struct net_device *netdev)
  259. {
  260. struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
  261. struct netdev_hw_addr *ha;
  262. struct net_device *real_dev;
  263. u8 flogi_maddr[ETH_ALEN];
  264. const struct net_device_ops *ops;
  265. fcoe->netdev = netdev;
  266. /* Let LLD initialize for FCoE */
  267. ops = netdev->netdev_ops;
  268. if (ops->ndo_fcoe_enable) {
  269. if (ops->ndo_fcoe_enable(netdev))
  270. FCOE_NETDEV_DBG(netdev, "Failed to enable FCoE"
  271. " specific feature for LLD.\n");
  272. }
  273. /* Do not support for bonding device */
  274. if (netdev->priv_flags & IFF_BONDING && netdev->flags & IFF_MASTER) {
  275. FCOE_NETDEV_DBG(netdev, "Bonded interfaces not supported\n");
  276. return -EOPNOTSUPP;
  277. }
  278. /* look for SAN MAC address, if multiple SAN MACs exist, only
  279. * use the first one for SPMA */
  280. real_dev = (netdev->priv_flags & IFF_802_1Q_VLAN) ?
  281. vlan_dev_real_dev(netdev) : netdev;
  282. fcoe->realdev = real_dev;
  283. rcu_read_lock();
  284. for_each_dev_addr(real_dev, ha) {
  285. if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
  286. (is_valid_ether_addr(ha->addr))) {
  287. memcpy(fip->ctl_src_addr, ha->addr, ETH_ALEN);
  288. fip->spma = 1;
  289. break;
  290. }
  291. }
  292. rcu_read_unlock();
  293. /* setup Source Mac Address */
  294. if (!fip->spma)
  295. memcpy(fip->ctl_src_addr, netdev->dev_addr, netdev->addr_len);
  296. /*
  297. * Add FCoE MAC address as second unicast MAC address
  298. * or enter promiscuous mode if not capable of listening
  299. * for multiple unicast MACs.
  300. */
  301. memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
  302. dev_uc_add(netdev, flogi_maddr);
  303. if (fip->spma)
  304. dev_uc_add(netdev, fip->ctl_src_addr);
  305. if (fip->mode == FIP_MODE_VN2VN) {
  306. dev_mc_add(netdev, FIP_ALL_VN2VN_MACS);
  307. dev_mc_add(netdev, FIP_ALL_P2P_MACS);
  308. } else
  309. dev_mc_add(netdev, FIP_ALL_ENODE_MACS);
  310. /*
  311. * setup the receive function from ethernet driver
  312. * on the ethertype for the given device
  313. */
  314. fcoe->fcoe_packet_type.func = fcoe_rcv;
  315. fcoe->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
  316. fcoe->fcoe_packet_type.dev = netdev;
  317. dev_add_pack(&fcoe->fcoe_packet_type);
  318. fcoe->fip_packet_type.func = fcoe_fip_recv;
  319. fcoe->fip_packet_type.type = htons(ETH_P_FIP);
  320. fcoe->fip_packet_type.dev = netdev;
  321. dev_add_pack(&fcoe->fip_packet_type);
  322. return 0;
  323. }
  324. /**
  325. * fcoe_interface_create() - Create a FCoE interface on a net device
  326. * @netdev: The net device to create the FCoE interface on
  327. * @fip_mode: The mode to use for FIP
  328. *
  329. * Returns: pointer to a struct fcoe_interface or NULL on error
  330. */
  331. static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
  332. enum fip_state fip_mode)
  333. {
  334. struct fcoe_ctlr_device *ctlr_dev;
  335. struct fcoe_ctlr *ctlr;
  336. struct fcoe_interface *fcoe;
  337. int size;
  338. int err;
  339. if (!try_module_get(THIS_MODULE)) {
  340. FCOE_NETDEV_DBG(netdev,
  341. "Could not get a reference to the module\n");
  342. fcoe = ERR_PTR(-EBUSY);
  343. goto out;
  344. }
  345. size = sizeof(struct fcoe_ctlr) + sizeof(struct fcoe_interface);
  346. ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &fcoe_sysfs_templ,
  347. size);
  348. if (!ctlr_dev) {
  349. FCOE_DBG("Failed to add fcoe_ctlr_device\n");
  350. fcoe = ERR_PTR(-ENOMEM);
  351. goto out_putmod;
  352. }
  353. ctlr = fcoe_ctlr_device_priv(ctlr_dev);
  354. fcoe = fcoe_ctlr_priv(ctlr);
  355. dev_hold(netdev);
  356. /*
  357. * Initialize FIP.
  358. */
  359. fcoe_ctlr_init(ctlr, fip_mode);
  360. ctlr->send = fcoe_fip_send;
  361. ctlr->update_mac = fcoe_update_src_mac;
  362. ctlr->get_src_addr = fcoe_get_src_mac;
  363. err = fcoe_interface_setup(fcoe, netdev);
  364. if (err) {
  365. fcoe_ctlr_destroy(ctlr);
  366. fcoe_ctlr_device_delete(ctlr_dev);
  367. dev_put(netdev);
  368. fcoe = ERR_PTR(err);
  369. goto out_putmod;
  370. }
  371. goto out;
  372. out_putmod:
  373. module_put(THIS_MODULE);
  374. out:
  375. return fcoe;
  376. }
  377. /**
  378. * fcoe_interface_remove() - remove FCoE interface from netdev
  379. * @fcoe: The FCoE interface to be cleaned up
  380. *
  381. * Caller must be holding the RTNL mutex
  382. */
  383. static void fcoe_interface_remove(struct fcoe_interface *fcoe)
  384. {
  385. struct net_device *netdev = fcoe->netdev;
  386. struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
  387. u8 flogi_maddr[ETH_ALEN];
  388. const struct net_device_ops *ops;
  389. /*
  390. * Don't listen for Ethernet packets anymore.
  391. * synchronize_net() ensures that the packet handlers are not running
  392. * on another CPU. dev_remove_pack() would do that, this calls the
  393. * unsyncronized version __dev_remove_pack() to avoid multiple delays.
  394. */
  395. __dev_remove_pack(&fcoe->fcoe_packet_type);
  396. __dev_remove_pack(&fcoe->fip_packet_type);
  397. synchronize_net();
  398. /* Delete secondary MAC addresses */
  399. memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
  400. dev_uc_del(netdev, flogi_maddr);
  401. if (fip->spma)
  402. dev_uc_del(netdev, fip->ctl_src_addr);
  403. if (fip->mode == FIP_MODE_VN2VN) {
  404. dev_mc_del(netdev, FIP_ALL_VN2VN_MACS);
  405. dev_mc_del(netdev, FIP_ALL_P2P_MACS);
  406. } else
  407. dev_mc_del(netdev, FIP_ALL_ENODE_MACS);
  408. /* Tell the LLD we are done w/ FCoE */
  409. ops = netdev->netdev_ops;
  410. if (ops->ndo_fcoe_disable) {
  411. if (ops->ndo_fcoe_disable(netdev))
  412. FCOE_NETDEV_DBG(netdev, "Failed to disable FCoE"
  413. " specific feature for LLD.\n");
  414. }
  415. fcoe->removed = 1;
  416. }
  417. /**
  418. * fcoe_interface_cleanup() - Clean up a FCoE interface
  419. * @fcoe: The FCoE interface to be cleaned up
  420. */
  421. static void fcoe_interface_cleanup(struct fcoe_interface *fcoe)
  422. {
  423. struct net_device *netdev = fcoe->netdev;
  424. struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
  425. rtnl_lock();
  426. if (!fcoe->removed)
  427. fcoe_interface_remove(fcoe);
  428. rtnl_unlock();
  429. /* Release the self-reference taken during fcoe_interface_create() */
  430. /* tear-down the FCoE controller */
  431. fcoe_ctlr_destroy(fip);
  432. scsi_host_put(fip->lp->host);
  433. dev_put(netdev);
  434. module_put(THIS_MODULE);
  435. }
  436. /**
  437. * fcoe_fip_recv() - Handler for received FIP frames
  438. * @skb: The receive skb
  439. * @netdev: The associated net device
  440. * @ptype: The packet_type structure which was used to register this handler
  441. * @orig_dev: The original net_device the the skb was received on.
  442. * (in case dev is a bond)
  443. *
  444. * Returns: 0 for success
  445. */
  446. static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *netdev,
  447. struct packet_type *ptype,
  448. struct net_device *orig_dev)
  449. {
  450. struct fcoe_interface *fcoe;
  451. struct fcoe_ctlr *ctlr;
  452. fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type);
  453. ctlr = fcoe_to_ctlr(fcoe);
  454. fcoe_ctlr_recv(ctlr, skb);
  455. return 0;
  456. }
  457. /**
  458. * fcoe_port_send() - Send an Ethernet-encapsulated FIP/FCoE frame
  459. * @port: The FCoE port
  460. * @skb: The FIP/FCoE packet to be sent
  461. */
  462. static void fcoe_port_send(struct fcoe_port *port, struct sk_buff *skb)
  463. {
  464. if (port->fcoe_pending_queue.qlen)
  465. fcoe_check_wait_queue(port->lport, skb);
  466. else if (fcoe_start_io(skb))
  467. fcoe_check_wait_queue(port->lport, skb);
  468. }
  469. /**
  470. * fcoe_fip_send() - Send an Ethernet-encapsulated FIP frame
  471. * @fip: The FCoE controller
  472. * @skb: The FIP packet to be sent
  473. */
  474. static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
  475. {
  476. skb->dev = fcoe_from_ctlr(fip)->netdev;
  477. fcoe_port_send(lport_priv(fip->lp), skb);
  478. }
  479. /**
  480. * fcoe_update_src_mac() - Update the Ethernet MAC filters
  481. * @lport: The local port to update the source MAC on
  482. * @addr: Unicast MAC address to add
  483. *
  484. * Remove any previously-set unicast MAC filter.
  485. * Add secondary FCoE MAC address filter for our OUI.
  486. */
  487. static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr)
  488. {
  489. struct fcoe_port *port = lport_priv(lport);
  490. struct fcoe_interface *fcoe = port->priv;
  491. if (!is_zero_ether_addr(port->data_src_addr))
  492. dev_uc_del(fcoe->netdev, port->data_src_addr);
  493. if (!is_zero_ether_addr(addr))
  494. dev_uc_add(fcoe->netdev, addr);
  495. memcpy(port->data_src_addr, addr, ETH_ALEN);
  496. }
  497. /**
  498. * fcoe_get_src_mac() - return the Ethernet source address for an lport
  499. * @lport: libfc lport
  500. */
  501. static u8 *fcoe_get_src_mac(struct fc_lport *lport)
  502. {
  503. struct fcoe_port *port = lport_priv(lport);
  504. return port->data_src_addr;
  505. }
  506. /**
  507. * fcoe_lport_config() - Set up a local port
  508. * @lport: The local port to be setup
  509. *
  510. * Returns: 0 for success
  511. */
  512. static int fcoe_lport_config(struct fc_lport *lport)
  513. {
  514. lport->link_up = 0;
  515. lport->qfull = 0;
  516. lport->max_retry_count = 3;
  517. lport->max_rport_retry_count = 3;
  518. lport->e_d_tov = 2 * 1000; /* FC-FS default */
  519. lport->r_a_tov = 2 * 2 * 1000;
  520. lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
  521. FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
  522. lport->does_npiv = 1;
  523. fc_lport_init_stats(lport);
  524. /* lport fc_lport related configuration */
  525. fc_lport_config(lport);
  526. /* offload related configuration */
  527. lport->crc_offload = 0;
  528. lport->seq_offload = 0;
  529. lport->lro_enabled = 0;
  530. lport->lro_xid = 0;
  531. lport->lso_max = 0;
  532. return 0;
  533. }
  534. /**
  535. * fcoe_netdev_features_change - Updates the lport's offload flags based
  536. * on the LLD netdev's FCoE feature flags
  537. */
  538. static void fcoe_netdev_features_change(struct fc_lport *lport,
  539. struct net_device *netdev)
  540. {
  541. mutex_lock(&lport->lp_mutex);
  542. if (netdev->features & NETIF_F_SG)
  543. lport->sg_supp = 1;
  544. else
  545. lport->sg_supp = 0;
  546. if (netdev->features & NETIF_F_FCOE_CRC) {
  547. lport->crc_offload = 1;
  548. FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n");
  549. } else {
  550. lport->crc_offload = 0;
  551. }
  552. if (netdev->features & NETIF_F_FSO) {
  553. lport->seq_offload = 1;
  554. lport->lso_max = netdev->gso_max_size;
  555. FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n",
  556. lport->lso_max);
  557. } else {
  558. lport->seq_offload = 0;
  559. lport->lso_max = 0;
  560. }
  561. if (netdev->fcoe_ddp_xid) {
  562. lport->lro_enabled = 1;
  563. lport->lro_xid = netdev->fcoe_ddp_xid;
  564. FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n",
  565. lport->lro_xid);
  566. } else {
  567. lport->lro_enabled = 0;
  568. lport->lro_xid = 0;
  569. }
  570. mutex_unlock(&lport->lp_mutex);
  571. }
  572. /**
  573. * fcoe_netdev_config() - Set up net devive for SW FCoE
  574. * @lport: The local port that is associated with the net device
  575. * @netdev: The associated net device
  576. *
  577. * Must be called after fcoe_lport_config() as it will use local port mutex
  578. *
  579. * Returns: 0 for success
  580. */
  581. static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev)
  582. {
  583. u32 mfs;
  584. u64 wwnn, wwpn;
  585. struct fcoe_interface *fcoe;
  586. struct fcoe_ctlr *ctlr;
  587. struct fcoe_port *port;
  588. /* Setup lport private data to point to fcoe softc */
  589. port = lport_priv(lport);
  590. fcoe = port->priv;
  591. ctlr = fcoe_to_ctlr(fcoe);
  592. /*
  593. * Determine max frame size based on underlying device and optional
  594. * user-configured limit. If the MFS is too low, fcoe_link_ok()
  595. * will return 0, so do this first.
  596. */
  597. mfs = netdev->mtu;
  598. if (netdev->features & NETIF_F_FCOE_MTU) {
  599. mfs = FCOE_MTU;
  600. FCOE_NETDEV_DBG(netdev, "Supports FCOE_MTU of %d bytes\n", mfs);
  601. }
  602. mfs -= (sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof));
  603. if (fc_set_mfs(lport, mfs))
  604. return -EINVAL;
  605. /* offload features support */
  606. fcoe_netdev_features_change(lport, netdev);
  607. skb_queue_head_init(&port->fcoe_pending_queue);
  608. port->fcoe_pending_queue_active = 0;
  609. setup_timer(&port->timer, fcoe_queue_timer, (unsigned long)lport);
  610. fcoe_link_speed_update(lport);
  611. if (!lport->vport) {
  612. if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
  613. wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr, 1, 0);
  614. fc_set_wwnn(lport, wwnn);
  615. if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
  616. wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
  617. 2, 0);
  618. fc_set_wwpn(lport, wwpn);
  619. }
  620. return 0;
  621. }
  622. /**
  623. * fcoe_shost_config() - Set up the SCSI host associated with a local port
  624. * @lport: The local port
  625. * @dev: The device associated with the SCSI host
  626. *
  627. * Must be called after fcoe_lport_config() and fcoe_netdev_config()
  628. *
  629. * Returns: 0 for success
  630. */
  631. static int fcoe_shost_config(struct fc_lport *lport, struct device *dev)
  632. {
  633. int rc = 0;
  634. /* lport scsi host config */
  635. lport->host->max_lun = FCOE_MAX_LUN;
  636. lport->host->max_id = FCOE_MAX_FCP_TARGET;
  637. lport->host->max_channel = 0;
  638. lport->host->max_cmd_len = FCOE_MAX_CMD_LEN;
  639. if (lport->vport)
  640. lport->host->transportt = fcoe_vport_scsi_transport;
  641. else
  642. lport->host->transportt = fcoe_nport_scsi_transport;
  643. /* add the new host to the SCSI-ml */
  644. rc = scsi_add_host(lport->host, dev);
  645. if (rc) {
  646. FCOE_NETDEV_DBG(fcoe_netdev(lport), "fcoe_shost_config: "
  647. "error on scsi_add_host\n");
  648. return rc;
  649. }
  650. if (!lport->vport)
  651. fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
  652. snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE,
  653. "%s v%s over %s", FCOE_NAME, FCOE_VERSION,
  654. fcoe_netdev(lport)->name);
  655. return 0;
  656. }
  657. /**
  658. * fcoe_fdmi_info() - Get FDMI related info from net devive for SW FCoE
  659. * @lport: The local port that is associated with the net device
  660. * @netdev: The associated net device
  661. *
  662. * Must be called after fcoe_shost_config() as it will use local port mutex
  663. *
  664. */
  665. static void fcoe_fdmi_info(struct fc_lport *lport, struct net_device *netdev)
  666. {
  667. struct fcoe_interface *fcoe;
  668. struct fcoe_port *port;
  669. struct net_device *realdev;
  670. int rc;
  671. port = lport_priv(lport);
  672. fcoe = port->priv;
  673. realdev = fcoe->realdev;
  674. if (!realdev)
  675. return;
  676. /* No FDMI state m/c for NPIV ports */
  677. if (lport->vport)
  678. return;
  679. if (realdev->netdev_ops->ndo_fcoe_get_hbainfo) {
  680. struct netdev_fcoe_hbainfo *fdmi;
  681. fdmi = kzalloc(sizeof(*fdmi), GFP_KERNEL);
  682. if (!fdmi)
  683. return;
  684. rc = realdev->netdev_ops->ndo_fcoe_get_hbainfo(realdev,
  685. fdmi);
  686. if (rc) {
  687. printk(KERN_INFO "fcoe: Failed to retrieve FDMI "
  688. "information from netdev.\n");
  689. return;
  690. }
  691. snprintf(fc_host_serial_number(lport->host),
  692. FC_SERIAL_NUMBER_SIZE,
  693. "%s",
  694. fdmi->serial_number);
  695. snprintf(fc_host_manufacturer(lport->host),
  696. FC_SERIAL_NUMBER_SIZE,
  697. "%s",
  698. fdmi->manufacturer);
  699. snprintf(fc_host_model(lport->host),
  700. FC_SYMBOLIC_NAME_SIZE,
  701. "%s",
  702. fdmi->model);
  703. snprintf(fc_host_model_description(lport->host),
  704. FC_SYMBOLIC_NAME_SIZE,
  705. "%s",
  706. fdmi->model_description);
  707. snprintf(fc_host_hardware_version(lport->host),
  708. FC_VERSION_STRING_SIZE,
  709. "%s",
  710. fdmi->hardware_version);
  711. snprintf(fc_host_driver_version(lport->host),
  712. FC_VERSION_STRING_SIZE,
  713. "%s",
  714. fdmi->driver_version);
  715. snprintf(fc_host_optionrom_version(lport->host),
  716. FC_VERSION_STRING_SIZE,
  717. "%s",
  718. fdmi->optionrom_version);
  719. snprintf(fc_host_firmware_version(lport->host),
  720. FC_VERSION_STRING_SIZE,
  721. "%s",
  722. fdmi->firmware_version);
  723. /* Enable FDMI lport states */
  724. lport->fdmi_enabled = 1;
  725. kfree(fdmi);
  726. } else {
  727. lport->fdmi_enabled = 0;
  728. printk(KERN_INFO "fcoe: No FDMI support.\n");
  729. }
  730. }
  731. /**
  732. * fcoe_oem_match() - The match routine for the offloaded exchange manager
  733. * @fp: The I/O frame
  734. *
  735. * This routine will be associated with an exchange manager (EM). When
  736. * the libfc exchange handling code is looking for an EM to use it will
  737. * call this routine and pass it the frame that it wishes to send. This
  738. * routine will return True if the associated EM is to be used and False
  739. * if the echange code should continue looking for an EM.
  740. *
  741. * The offload EM that this routine is associated with will handle any
  742. * packets that are for SCSI read requests.
  743. *
  744. * This has been enhanced to work when FCoE stack is operating in target
  745. * mode.
  746. *
  747. * Returns: True for read types I/O, otherwise returns false.
  748. */
  749. static bool fcoe_oem_match(struct fc_frame *fp)
  750. {
  751. struct fc_frame_header *fh = fc_frame_header_get(fp);
  752. struct fcp_cmnd *fcp;
  753. if (fc_fcp_is_read(fr_fsp(fp)) &&
  754. (fr_fsp(fp)->data_len > fcoe_ddp_min))
  755. return true;
  756. else if ((fr_fsp(fp) == NULL) &&
  757. (fh->fh_r_ctl == FC_RCTL_DD_UNSOL_CMD) &&
  758. (ntohs(fh->fh_rx_id) == FC_XID_UNKNOWN)) {
  759. fcp = fc_frame_payload_get(fp, sizeof(*fcp));
  760. if ((fcp->fc_flags & FCP_CFL_WRDATA) &&
  761. (ntohl(fcp->fc_dl) > fcoe_ddp_min))
  762. return true;
  763. }
  764. return false;
  765. }
  766. /**
  767. * fcoe_em_config() - Allocate and configure an exchange manager
  768. * @lport: The local port that the new EM will be associated with
  769. *
  770. * Returns: 0 on success
  771. */
  772. static inline int fcoe_em_config(struct fc_lport *lport)
  773. {
  774. struct fcoe_port *port = lport_priv(lport);
  775. struct fcoe_interface *fcoe = port->priv;
  776. struct fcoe_interface *oldfcoe = NULL;
  777. struct net_device *old_real_dev, *cur_real_dev;
  778. u16 min_xid = FCOE_MIN_XID;
  779. u16 max_xid = FCOE_MAX_XID;
  780. /*
  781. * Check if need to allocate an em instance for
  782. * offload exchange ids to be shared across all VN_PORTs/lport.
  783. */
  784. if (!lport->lro_enabled || !lport->lro_xid ||
  785. (lport->lro_xid >= max_xid)) {
  786. lport->lro_xid = 0;
  787. goto skip_oem;
  788. }
  789. /*
  790. * Reuse existing offload em instance in case
  791. * it is already allocated on real eth device
  792. */
  793. if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
  794. cur_real_dev = vlan_dev_real_dev(fcoe->netdev);
  795. else
  796. cur_real_dev = fcoe->netdev;
  797. list_for_each_entry(oldfcoe, &fcoe_hostlist, list) {
  798. if (oldfcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
  799. old_real_dev = vlan_dev_real_dev(oldfcoe->netdev);
  800. else
  801. old_real_dev = oldfcoe->netdev;
  802. if (cur_real_dev == old_real_dev) {
  803. fcoe->oem = oldfcoe->oem;
  804. break;
  805. }
  806. }
  807. if (fcoe->oem) {
  808. if (!fc_exch_mgr_add(lport, fcoe->oem, fcoe_oem_match)) {
  809. printk(KERN_ERR "fcoe_em_config: failed to add "
  810. "offload em:%p on interface:%s\n",
  811. fcoe->oem, fcoe->netdev->name);
  812. return -ENOMEM;
  813. }
  814. } else {
  815. fcoe->oem = fc_exch_mgr_alloc(lport, FC_CLASS_3,
  816. FCOE_MIN_XID, lport->lro_xid,
  817. fcoe_oem_match);
  818. if (!fcoe->oem) {
  819. printk(KERN_ERR "fcoe_em_config: failed to allocate "
  820. "em for offload exches on interface:%s\n",
  821. fcoe->netdev->name);
  822. return -ENOMEM;
  823. }
  824. }
  825. /*
  826. * Exclude offload EM xid range from next EM xid range.
  827. */
  828. min_xid += lport->lro_xid + 1;
  829. skip_oem:
  830. if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, min_xid, max_xid, NULL)) {
  831. printk(KERN_ERR "fcoe_em_config: failed to "
  832. "allocate em on interface %s\n", fcoe->netdev->name);
  833. return -ENOMEM;
  834. }
  835. return 0;
  836. }
  837. /**
  838. * fcoe_if_destroy() - Tear down a SW FCoE instance
  839. * @lport: The local port to be destroyed
  840. *
  841. */
  842. static void fcoe_if_destroy(struct fc_lport *lport)
  843. {
  844. struct fcoe_port *port = lport_priv(lport);
  845. struct fcoe_interface *fcoe = port->priv;
  846. struct net_device *netdev = fcoe->netdev;
  847. FCOE_NETDEV_DBG(netdev, "Destroying interface\n");
  848. /* Logout of the fabric */
  849. fc_fabric_logoff(lport);
  850. /* Cleanup the fc_lport */
  851. fc_lport_destroy(lport);
  852. /* Stop the transmit retry timer */
  853. del_timer_sync(&port->timer);
  854. /* Free existing transmit skbs */
  855. fcoe_clean_pending_queue(lport);
  856. rtnl_lock();
  857. if (!is_zero_ether_addr(port->data_src_addr))
  858. dev_uc_del(netdev, port->data_src_addr);
  859. if (lport->vport)
  860. synchronize_net();
  861. else
  862. fcoe_interface_remove(fcoe);
  863. rtnl_unlock();
  864. /* Free queued packets for the per-CPU receive threads */
  865. fcoe_percpu_clean(lport);
  866. /* Detach from the scsi-ml */
  867. fc_remove_host(lport->host);
  868. scsi_remove_host(lport->host);
  869. /* Destroy lport scsi_priv */
  870. fc_fcp_destroy(lport);
  871. /* There are no more rports or I/O, free the EM */
  872. fc_exch_mgr_free(lport);
  873. /* Free memory used by statistical counters */
  874. fc_lport_free_stats(lport);
  875. /*
  876. * Release the Scsi_Host for vport but hold on to
  877. * master lport until it fcoe interface fully cleaned-up.
  878. */
  879. if (lport->vport)
  880. scsi_host_put(lport->host);
  881. }
  882. /**
  883. * fcoe_ddp_setup() - Call a LLD's ddp_setup through the net device
  884. * @lport: The local port to setup DDP for
  885. * @xid: The exchange ID for this DDP transfer
  886. * @sgl: The scatterlist describing this transfer
  887. * @sgc: The number of sg items
  888. *
  889. * Returns: 0 if the DDP context was not configured
  890. */
  891. static int fcoe_ddp_setup(struct fc_lport *lport, u16 xid,
  892. struct scatterlist *sgl, unsigned int sgc)
  893. {
  894. struct net_device *netdev = fcoe_netdev(lport);
  895. if (netdev->netdev_ops->ndo_fcoe_ddp_setup)
  896. return netdev->netdev_ops->ndo_fcoe_ddp_setup(netdev,
  897. xid, sgl,
  898. sgc);
  899. return 0;
  900. }
  901. /**
  902. * fcoe_ddp_target() - Call a LLD's ddp_target through the net device
  903. * @lport: The local port to setup DDP for
  904. * @xid: The exchange ID for this DDP transfer
  905. * @sgl: The scatterlist describing this transfer
  906. * @sgc: The number of sg items
  907. *
  908. * Returns: 0 if the DDP context was not configured
  909. */
  910. static int fcoe_ddp_target(struct fc_lport *lport, u16 xid,
  911. struct scatterlist *sgl, unsigned int sgc)
  912. {
  913. struct net_device *netdev = fcoe_netdev(lport);
  914. if (netdev->netdev_ops->ndo_fcoe_ddp_target)
  915. return netdev->netdev_ops->ndo_fcoe_ddp_target(netdev, xid,
  916. sgl, sgc);
  917. return 0;
  918. }
  919. /**
  920. * fcoe_ddp_done() - Call a LLD's ddp_done through the net device
  921. * @lport: The local port to complete DDP on
  922. * @xid: The exchange ID for this DDP transfer
  923. *
  924. * Returns: the length of data that have been completed by DDP
  925. */
  926. static int fcoe_ddp_done(struct fc_lport *lport, u16 xid)
  927. {
  928. struct net_device *netdev = fcoe_netdev(lport);
  929. if (netdev->netdev_ops->ndo_fcoe_ddp_done)
  930. return netdev->netdev_ops->ndo_fcoe_ddp_done(netdev, xid);
  931. return 0;
  932. }
  933. /**
  934. * fcoe_if_create() - Create a FCoE instance on an interface
  935. * @fcoe: The FCoE interface to create a local port on
  936. * @parent: The device pointer to be the parent in sysfs for the SCSI host
  937. * @npiv: Indicates if the port is a vport or not
  938. *
  939. * Creates a fc_lport instance and a Scsi_Host instance and configure them.
  940. *
  941. * Returns: The allocated fc_lport or an error pointer
  942. */
  943. static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
  944. struct device *parent, int npiv)
  945. {
  946. struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
  947. struct net_device *netdev = fcoe->netdev;
  948. struct fc_lport *lport, *n_port;
  949. struct fcoe_port *port;
  950. struct Scsi_Host *shost;
  951. int rc;
  952. /*
  953. * parent is only a vport if npiv is 1,
  954. * but we'll only use vport in that case so go ahead and set it
  955. */
  956. struct fc_vport *vport = dev_to_vport(parent);
  957. FCOE_NETDEV_DBG(netdev, "Create Interface\n");
  958. if (!npiv)
  959. lport = libfc_host_alloc(&fcoe_shost_template, sizeof(*port));
  960. else
  961. lport = libfc_vport_create(vport, sizeof(*port));
  962. if (!lport) {
  963. FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n");
  964. rc = -ENOMEM;
  965. goto out;
  966. }
  967. port = lport_priv(lport);
  968. port->lport = lport;
  969. port->priv = fcoe;
  970. port->get_netdev = fcoe_netdev;
  971. port->max_queue_depth = FCOE_MAX_QUEUE_DEPTH;
  972. port->min_queue_depth = FCOE_MIN_QUEUE_DEPTH;
  973. INIT_WORK(&port->destroy_work, fcoe_destroy_work);
  974. /*
  975. * Need to add the lport to the hostlist
  976. * so we catch NETDEV_CHANGE events.
  977. */
  978. fcoe_hostlist_add(lport);
  979. /* configure a fc_lport including the exchange manager */
  980. rc = fcoe_lport_config(lport);
  981. if (rc) {
  982. FCOE_NETDEV_DBG(netdev, "Could not configure lport for the "
  983. "interface\n");
  984. goto out_host_put;
  985. }
  986. if (npiv) {
  987. FCOE_NETDEV_DBG(netdev, "Setting vport names, "
  988. "%16.16llx %16.16llx\n",
  989. vport->node_name, vport->port_name);
  990. fc_set_wwnn(lport, vport->node_name);
  991. fc_set_wwpn(lport, vport->port_name);
  992. }
  993. /* configure lport network properties */
  994. rc = fcoe_netdev_config(lport, netdev);
  995. if (rc) {
  996. FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the "
  997. "interface\n");
  998. goto out_lp_destroy;
  999. }
  1000. /* configure lport scsi host properties */
  1001. rc = fcoe_shost_config(lport, parent);
  1002. if (rc) {
  1003. FCOE_NETDEV_DBG(netdev, "Could not configure shost for the "
  1004. "interface\n");
  1005. goto out_lp_destroy;
  1006. }
  1007. /* Initialize the library */
  1008. rc = fcoe_libfc_config(lport, ctlr, &fcoe_libfc_fcn_templ, 1);
  1009. if (rc) {
  1010. FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the "
  1011. "interface\n");
  1012. goto out_lp_destroy;
  1013. }
  1014. /* Initialized FDMI information */
  1015. fcoe_fdmi_info(lport, netdev);
  1016. /*
  1017. * fcoe_em_alloc() and fcoe_hostlist_add() both
  1018. * need to be atomic with respect to other changes to the
  1019. * hostlist since fcoe_em_alloc() looks for an existing EM
  1020. * instance on host list updated by fcoe_hostlist_add().
  1021. *
  1022. * This is currently handled through the fcoe_config_mutex
  1023. * begin held.
  1024. */
  1025. if (!npiv)
  1026. /* lport exch manager allocation */
  1027. rc = fcoe_em_config(lport);
  1028. else {
  1029. shost = vport_to_shost(vport);
  1030. n_port = shost_priv(shost);
  1031. rc = fc_exch_mgr_list_clone(n_port, lport);
  1032. }
  1033. if (rc) {
  1034. FCOE_NETDEV_DBG(netdev, "Could not configure the EM\n");
  1035. goto out_lp_destroy;
  1036. }
  1037. return lport;
  1038. out_lp_destroy:
  1039. fc_exch_mgr_free(lport);
  1040. out_host_put:
  1041. fcoe_hostlist_del(lport);
  1042. scsi_host_put(lport->host);
  1043. out:
  1044. return ERR_PTR(rc);
  1045. }
  1046. /**
  1047. * fcoe_if_init() - Initialization routine for fcoe.ko
  1048. *
  1049. * Attaches the SW FCoE transport to the FC transport
  1050. *
  1051. * Returns: 0 on success
  1052. */
  1053. static int __init fcoe_if_init(void)
  1054. {
  1055. /* attach to scsi transport */
  1056. fcoe_nport_scsi_transport =
  1057. fc_attach_transport(&fcoe_nport_fc_functions);
  1058. fcoe_vport_scsi_transport =
  1059. fc_attach_transport(&fcoe_vport_fc_functions);
  1060. if (!fcoe_nport_scsi_transport) {
  1061. printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
  1062. return -ENODEV;
  1063. }
  1064. return 0;
  1065. }
  1066. /**
  1067. * fcoe_if_exit() - Tear down fcoe.ko
  1068. *
  1069. * Detaches the SW FCoE transport from the FC transport
  1070. *
  1071. * Returns: 0 on success
  1072. */
  1073. static int __exit fcoe_if_exit(void)
  1074. {
  1075. fc_release_transport(fcoe_nport_scsi_transport);
  1076. fc_release_transport(fcoe_vport_scsi_transport);
  1077. fcoe_nport_scsi_transport = NULL;
  1078. fcoe_vport_scsi_transport = NULL;
  1079. return 0;
  1080. }
  1081. /**
  1082. * fcoe_percpu_thread_create() - Create a receive thread for an online CPU
  1083. * @cpu: The CPU index of the CPU to create a receive thread for
  1084. */
  1085. static void fcoe_percpu_thread_create(unsigned int cpu)
  1086. {
  1087. struct fcoe_percpu_s *p;
  1088. struct task_struct *thread;
  1089. p = &per_cpu(fcoe_percpu, cpu);
  1090. thread = kthread_create_on_node(fcoe_percpu_receive_thread,
  1091. (void *)p, cpu_to_node(cpu),
  1092. "fcoethread/%d", cpu);
  1093. if (likely(!IS_ERR(thread))) {
  1094. kthread_bind(thread, cpu);
  1095. wake_up_process(thread);
  1096. spin_lock_bh(&p->fcoe_rx_list.lock);
  1097. p->thread = thread;
  1098. spin_unlock_bh(&p->fcoe_rx_list.lock);
  1099. }
  1100. }
  1101. /**
  1102. * fcoe_percpu_thread_destroy() - Remove the receive thread of a CPU
  1103. * @cpu: The CPU index of the CPU whose receive thread is to be destroyed
  1104. *
  1105. * Destroys a per-CPU Rx thread. Any pending skbs are moved to the
  1106. * current CPU's Rx thread. If the thread being destroyed is bound to
  1107. * the CPU processing this context the skbs will be freed.
  1108. */
  1109. static void fcoe_percpu_thread_destroy(unsigned int cpu)
  1110. {
  1111. struct fcoe_percpu_s *p;
  1112. struct task_struct *thread;
  1113. struct page *crc_eof;
  1114. struct sk_buff *skb;
  1115. #ifdef CONFIG_SMP
  1116. struct fcoe_percpu_s *p0;
  1117. unsigned targ_cpu = get_cpu();
  1118. #endif /* CONFIG_SMP */
  1119. FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
  1120. /* Prevent any new skbs from being queued for this CPU. */
  1121. p = &per_cpu(fcoe_percpu, cpu);
  1122. spin_lock_bh(&p->fcoe_rx_list.lock);
  1123. thread = p->thread;
  1124. p->thread = NULL;
  1125. crc_eof = p->crc_eof_page;
  1126. p->crc_eof_page = NULL;
  1127. p->crc_eof_offset = 0;
  1128. spin_unlock_bh(&p->fcoe_rx_list.lock);
  1129. #ifdef CONFIG_SMP
  1130. /*
  1131. * Don't bother moving the skb's if this context is running
  1132. * on the same CPU that is having its thread destroyed. This
  1133. * can easily happen when the module is removed.
  1134. */
  1135. if (cpu != targ_cpu) {
  1136. p0 = &per_cpu(fcoe_percpu, targ_cpu);
  1137. spin_lock_bh(&p0->fcoe_rx_list.lock);
  1138. if (p0->thread) {
  1139. FCOE_DBG("Moving frames from CPU %d to CPU %d\n",
  1140. cpu, targ_cpu);
  1141. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  1142. __skb_queue_tail(&p0->fcoe_rx_list, skb);
  1143. spin_unlock_bh(&p0->fcoe_rx_list.lock);
  1144. } else {
  1145. /*
  1146. * The targeted CPU is not initialized and cannot accept
  1147. * new skbs. Unlock the targeted CPU and drop the skbs
  1148. * on the CPU that is going offline.
  1149. */
  1150. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  1151. kfree_skb(skb);
  1152. spin_unlock_bh(&p0->fcoe_rx_list.lock);
  1153. }
  1154. } else {
  1155. /*
  1156. * This scenario occurs when the module is being removed
  1157. * and all threads are being destroyed. skbs will continue
  1158. * to be shifted from the CPU thread that is being removed
  1159. * to the CPU thread associated with the CPU that is processing
  1160. * the module removal. Once there is only one CPU Rx thread it
  1161. * will reach this case and we will drop all skbs and later
  1162. * stop the thread.
  1163. */
  1164. spin_lock_bh(&p->fcoe_rx_list.lock);
  1165. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  1166. kfree_skb(skb);
  1167. spin_unlock_bh(&p->fcoe_rx_list.lock);
  1168. }
  1169. put_cpu();
  1170. #else
  1171. /*
  1172. * This a non-SMP scenario where the singular Rx thread is
  1173. * being removed. Free all skbs and stop the thread.
  1174. */
  1175. spin_lock_bh(&p->fcoe_rx_list.lock);
  1176. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  1177. kfree_skb(skb);
  1178. spin_unlock_bh(&p->fcoe_rx_list.lock);
  1179. #endif
  1180. if (thread)
  1181. kthread_stop(thread);
  1182. if (crc_eof)
  1183. put_page(crc_eof);
  1184. }
  1185. /**
  1186. * fcoe_cpu_callback() - Handler for CPU hotplug events
  1187. * @nfb: The callback data block
  1188. * @action: The event triggering the callback
  1189. * @hcpu: The index of the CPU that the event is for
  1190. *
  1191. * This creates or destroys per-CPU data for fcoe
  1192. *
  1193. * Returns NOTIFY_OK always.
  1194. */
  1195. static int fcoe_cpu_callback(struct notifier_block *nfb,
  1196. unsigned long action, void *hcpu)
  1197. {
  1198. unsigned cpu = (unsigned long)hcpu;
  1199. switch (action) {
  1200. case CPU_ONLINE:
  1201. case CPU_ONLINE_FROZEN:
  1202. FCOE_DBG("CPU %x online: Create Rx thread\n", cpu);
  1203. fcoe_percpu_thread_create(cpu);
  1204. break;
  1205. case CPU_DEAD:
  1206. case CPU_DEAD_FROZEN:
  1207. FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu);
  1208. fcoe_percpu_thread_destroy(cpu);
  1209. break;
  1210. default:
  1211. break;
  1212. }
  1213. return NOTIFY_OK;
  1214. }
  1215. /**
  1216. * fcoe_select_cpu() - Selects CPU to handle post-processing of incoming
  1217. * command.
  1218. *
  1219. * This routine selects next CPU based on cpumask to distribute
  1220. * incoming requests in round robin.
  1221. *
  1222. * Returns: int CPU number
  1223. */
  1224. static inline unsigned int fcoe_select_cpu(void)
  1225. {
  1226. static unsigned int selected_cpu;
  1227. selected_cpu = cpumask_next(selected_cpu, cpu_online_mask);
  1228. if (selected_cpu >= nr_cpu_ids)
  1229. selected_cpu = cpumask_first(cpu_online_mask);
  1230. return selected_cpu;
  1231. }
  1232. /**
  1233. * fcoe_rcv() - Receive packets from a net device
  1234. * @skb: The received packet
  1235. * @netdev: The net device that the packet was received on
  1236. * @ptype: The packet type context
  1237. * @olddev: The last device net device
  1238. *
  1239. * This routine is called by NET_RX_SOFTIRQ. It receives a packet, builds a
  1240. * FC frame and passes the frame to libfc.
  1241. *
  1242. * Returns: 0 for success
  1243. */
  1244. static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
  1245. struct packet_type *ptype, struct net_device *olddev)
  1246. {
  1247. struct fc_lport *lport;
  1248. struct fcoe_rcv_info *fr;
  1249. struct fcoe_ctlr *ctlr;
  1250. struct fcoe_interface *fcoe;
  1251. struct fc_frame_header *fh;
  1252. struct fcoe_percpu_s *fps;
  1253. struct ethhdr *eh;
  1254. unsigned int cpu;
  1255. fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type);
  1256. ctlr = fcoe_to_ctlr(fcoe);
  1257. lport = ctlr->lp;
  1258. if (unlikely(!lport)) {
  1259. FCOE_NETDEV_DBG(netdev, "Cannot find hba structure");
  1260. goto err2;
  1261. }
  1262. if (!lport->link_up)
  1263. goto err2;
  1264. FCOE_NETDEV_DBG(netdev, "skb_info: len:%d data_len:%d head:%p "
  1265. "data:%p tail:%p end:%p sum:%d dev:%s",
  1266. skb->len, skb->data_len, skb->head, skb->data,
  1267. skb_tail_pointer(skb), skb_end_pointer(skb),
  1268. skb->csum, skb->dev ? skb->dev->name : "<NULL>");
  1269. skb = skb_share_check(skb, GFP_ATOMIC);
  1270. if (skb == NULL)
  1271. return NET_RX_DROP;
  1272. eh = eth_hdr(skb);
  1273. if (is_fip_mode(ctlr) &&
  1274. compare_ether_addr(eh->h_source, ctlr->dest_addr)) {
  1275. FCOE_NETDEV_DBG(netdev, "wrong source mac address:%pM\n",
  1276. eh->h_source);
  1277. goto err;
  1278. }
  1279. /*
  1280. * Check for minimum frame length, and make sure required FCoE
  1281. * and FC headers are pulled into the linear data area.
  1282. */
  1283. if (unlikely((skb->len < FCOE_MIN_FRAME) ||
  1284. !pskb_may_pull(skb, FCOE_HEADER_LEN)))
  1285. goto err;
  1286. skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
  1287. fh = (struct fc_frame_header *) skb_transport_header(skb);
  1288. if (ntoh24(&eh->h_dest[3]) != ntoh24(fh->fh_d_id)) {
  1289. FCOE_NETDEV_DBG(netdev, "FC frame d_id mismatch with MAC:%pM\n",
  1290. eh->h_dest);
  1291. goto err;
  1292. }
  1293. fr = fcoe_dev_from_skb(skb);
  1294. fr->fr_dev = lport;
  1295. /*
  1296. * In case the incoming frame's exchange is originated from
  1297. * the initiator, then received frame's exchange id is ANDed
  1298. * with fc_cpu_mask bits to get the same cpu on which exchange
  1299. * was originated, otherwise select cpu using rx exchange id
  1300. * or fcoe_select_cpu().
  1301. */
  1302. if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX)
  1303. cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask;
  1304. else {
  1305. if (ntohs(fh->fh_rx_id) == FC_XID_UNKNOWN)
  1306. cpu = fcoe_select_cpu();
  1307. else
  1308. cpu = ntohs(fh->fh_rx_id) & fc_cpu_mask;
  1309. }
  1310. if (cpu >= nr_cpu_ids)
  1311. goto err;
  1312. fps = &per_cpu(fcoe_percpu, cpu);
  1313. spin_lock(&fps->fcoe_rx_list.lock);
  1314. if (unlikely(!fps->thread)) {
  1315. /*
  1316. * The targeted CPU is not ready, let's target
  1317. * the first CPU now. For non-SMP systems this
  1318. * will check the same CPU twice.
  1319. */
  1320. FCOE_NETDEV_DBG(netdev, "CPU is online, but no receive thread "
  1321. "ready for incoming skb- using first online "
  1322. "CPU.\n");
  1323. spin_unlock(&fps->fcoe_rx_list.lock);
  1324. cpu = cpumask_first(cpu_online_mask);
  1325. fps = &per_cpu(fcoe_percpu, cpu);
  1326. spin_lock(&fps->fcoe_rx_list.lock);
  1327. if (!fps->thread) {
  1328. spin_unlock(&fps->fcoe_rx_list.lock);
  1329. goto err;
  1330. }
  1331. }
  1332. /*
  1333. * We now have a valid CPU that we're targeting for
  1334. * this skb. We also have this receive thread locked,
  1335. * so we're free to queue skbs into it's queue.
  1336. */
  1337. /*
  1338. * Note: We used to have a set of conditions under which we would
  1339. * call fcoe_recv_frame directly, rather than queuing to the rx list
  1340. * as it could save a few cycles, but doing so is prohibited, as
  1341. * fcoe_recv_frame has several paths that may sleep, which is forbidden
  1342. * in softirq context.
  1343. */
  1344. __skb_queue_tail(&fps->fcoe_rx_list, skb);
  1345. if (fps->thread->state == TASK_INTERRUPTIBLE)
  1346. wake_up_process(fps->thread);
  1347. spin_unlock(&fps->fcoe_rx_list.lock);
  1348. return NET_RX_SUCCESS;
  1349. err:
  1350. per_cpu_ptr(lport->stats, get_cpu())->ErrorFrames++;
  1351. put_cpu();
  1352. err2:
  1353. kfree_skb(skb);
  1354. return NET_RX_DROP;
  1355. }
  1356. /**
  1357. * fcoe_alloc_paged_crc_eof() - Allocate a page to be used for the trailer CRC
  1358. * @skb: The packet to be transmitted
  1359. * @tlen: The total length of the trailer
  1360. *
  1361. * Returns: 0 for success
  1362. */
  1363. static int fcoe_alloc_paged_crc_eof(struct sk_buff *skb, int tlen)
  1364. {
  1365. struct fcoe_percpu_s *fps;
  1366. int rc;
  1367. fps = &get_cpu_var(fcoe_percpu);
  1368. rc = fcoe_get_paged_crc_eof(skb, tlen, fps);
  1369. put_cpu_var(fcoe_percpu);
  1370. return rc;
  1371. }
  1372. /**
  1373. * fcoe_xmit() - Transmit a FCoE frame
  1374. * @lport: The local port that the frame is to be transmitted for
  1375. * @fp: The frame to be transmitted
  1376. *
  1377. * Return: 0 for success
  1378. */
  1379. static int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp)
  1380. {
  1381. int wlen;
  1382. u32 crc;
  1383. struct ethhdr *eh;
  1384. struct fcoe_crc_eof *cp;
  1385. struct sk_buff *skb;
  1386. struct fc_stats *stats;
  1387. struct fc_frame_header *fh;
  1388. unsigned int hlen; /* header length implies the version */
  1389. unsigned int tlen; /* trailer length */
  1390. unsigned int elen; /* eth header, may include vlan */
  1391. struct fcoe_port *port = lport_priv(lport);
  1392. struct fcoe_interface *fcoe = port->priv;
  1393. struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
  1394. u8 sof, eof;
  1395. struct fcoe_hdr *hp;
  1396. WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
  1397. fh = fc_frame_header_get(fp);
  1398. skb = fp_skb(fp);
  1399. wlen = skb->len / FCOE_WORD_TO_BYTE;
  1400. if (!lport->link_up) {
  1401. kfree_skb(skb);
  1402. return 0;
  1403. }
  1404. if (unlikely(fh->fh_type == FC_TYPE_ELS) &&
  1405. fcoe_ctlr_els_send(ctlr, lport, skb))
  1406. return 0;
  1407. sof = fr_sof(fp);
  1408. eof = fr_eof(fp);
  1409. elen = sizeof(struct ethhdr);
  1410. hlen = sizeof(struct fcoe_hdr);
  1411. tlen = sizeof(struct fcoe_crc_eof);
  1412. wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
  1413. /* crc offload */
  1414. if (likely(lport->crc_offload)) {
  1415. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1416. skb->csum_start = skb_headroom(skb);
  1417. skb->csum_offset = skb->len;
  1418. crc = 0;
  1419. } else {
  1420. skb->ip_summed = CHECKSUM_NONE;
  1421. crc = fcoe_fc_crc(fp);
  1422. }
  1423. /* copy port crc and eof to the skb buff */
  1424. if (skb_is_nonlinear(skb)) {
  1425. skb_frag_t *frag;
  1426. if (fcoe_alloc_paged_crc_eof(skb, tlen)) {
  1427. kfree_skb(skb);
  1428. return -ENOMEM;
  1429. }
  1430. frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
  1431. cp = kmap_atomic(skb_frag_page(frag))
  1432. + frag->page_offset;
  1433. } else {
  1434. cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
  1435. }
  1436. memset(cp, 0, sizeof(*cp));
  1437. cp->fcoe_eof = eof;
  1438. cp->fcoe_crc32 = cpu_to_le32(~crc);
  1439. if (skb_is_nonlinear(skb)) {
  1440. kunmap_atomic(cp);
  1441. cp = NULL;
  1442. }
  1443. /* adjust skb network/transport offsets to match mac/fcoe/port */
  1444. skb_push(skb, elen + hlen);
  1445. skb_reset_mac_header(skb);
  1446. skb_reset_network_header(skb);
  1447. skb->mac_len = elen;
  1448. skb->protocol = htons(ETH_P_FCOE);
  1449. skb->priority = fcoe->priority;
  1450. if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN &&
  1451. fcoe->realdev->features & NETIF_F_HW_VLAN_CTAG_TX) {
  1452. /* must set skb->dev before calling vlan_put_tag */
  1453. skb->dev = fcoe->realdev;
  1454. skb = __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
  1455. vlan_dev_vlan_id(fcoe->netdev));
  1456. if (!skb)
  1457. return -ENOMEM;
  1458. } else
  1459. skb->dev = fcoe->netdev;
  1460. /* fill up mac and fcoe headers */
  1461. eh = eth_hdr(skb);
  1462. eh->h_proto = htons(ETH_P_FCOE);
  1463. memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
  1464. if (ctlr->map_dest)
  1465. memcpy(eh->h_dest + 3, fh->fh_d_id, 3);
  1466. if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
  1467. memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
  1468. else
  1469. memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
  1470. hp = (struct fcoe_hdr *)(eh + 1);
  1471. memset(hp, 0, sizeof(*hp));
  1472. if (FC_FCOE_VER)
  1473. FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
  1474. hp->fcoe_sof = sof;
  1475. /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
  1476. if (lport->seq_offload && fr_max_payload(fp)) {
  1477. skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
  1478. skb_shinfo(skb)->gso_size = fr_max_payload(fp);
  1479. } else {
  1480. skb_shinfo(skb)->gso_type = 0;
  1481. skb_shinfo(skb)->gso_size = 0;
  1482. }
  1483. /* update tx stats: regardless if LLD fails */
  1484. stats = per_cpu_ptr(lport->stats, get_cpu());
  1485. stats->TxFrames++;
  1486. stats->TxWords += wlen;
  1487. put_cpu();
  1488. /* send down to lld */
  1489. fr_dev(fp) = lport;
  1490. fcoe_port_send(port, skb);
  1491. return 0;
  1492. }
  1493. /**
  1494. * fcoe_percpu_flush_done() - Indicate per-CPU queue flush completion
  1495. * @skb: The completed skb (argument required by destructor)
  1496. */
  1497. static void fcoe_percpu_flush_done(struct sk_buff *skb)
  1498. {
  1499. complete(&fcoe_flush_completion);
  1500. }
  1501. /**
  1502. * fcoe_filter_frames() - filter out bad fcoe frames, i.e. bad CRC
  1503. * @lport: The local port the frame was received on
  1504. * @fp: The received frame
  1505. *
  1506. * Return: 0 on passing filtering checks
  1507. */
  1508. static inline int fcoe_filter_frames(struct fc_lport *lport,
  1509. struct fc_frame *fp)
  1510. {
  1511. struct fcoe_ctlr *ctlr;
  1512. struct fcoe_interface *fcoe;
  1513. struct fc_frame_header *fh;
  1514. struct sk_buff *skb = (struct sk_buff *)fp;
  1515. struct fc_stats *stats;
  1516. /*
  1517. * We only check CRC if no offload is available and if it is
  1518. * it's solicited data, in which case, the FCP layer would
  1519. * check it during the copy.
  1520. */
  1521. if (lport->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
  1522. fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
  1523. else
  1524. fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
  1525. fh = (struct fc_frame_header *) skb_transport_header(skb);
  1526. fh = fc_frame_header_get(fp);
  1527. if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && fh->fh_type == FC_TYPE_FCP)
  1528. return 0;
  1529. fcoe = ((struct fcoe_port *)lport_priv(lport))->priv;
  1530. ctlr = fcoe_to_ctlr(fcoe);
  1531. if (is_fip_mode(ctlr) && fc_frame_payload_op(fp) == ELS_LOGO &&
  1532. ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
  1533. FCOE_DBG("fcoe: dropping FCoE lport LOGO in fip mode\n");
  1534. return -EINVAL;
  1535. }
  1536. if (!(fr_flags(fp) & FCPHF_CRC_UNCHECKED) ||
  1537. le32_to_cpu(fr_crc(fp)) == ~crc32(~0, skb->data, skb->len)) {
  1538. fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
  1539. return 0;
  1540. }
  1541. stats = per_cpu_ptr(lport->stats, get_cpu());
  1542. stats->InvalidCRCCount++;
  1543. if (stats->InvalidCRCCount < 5)
  1544. printk(KERN_WARNING "fcoe: dropping frame with CRC error\n");
  1545. put_cpu();
  1546. return -EINVAL;
  1547. }
  1548. /**
  1549. * fcoe_recv_frame() - process a single received frame
  1550. * @skb: frame to process
  1551. */
  1552. static void fcoe_recv_frame(struct sk_buff *skb)
  1553. {
  1554. u32 fr_len;
  1555. struct fc_lport *lport;
  1556. struct fcoe_rcv_info *fr;
  1557. struct fc_stats *stats;
  1558. struct fcoe_crc_eof crc_eof;
  1559. struct fc_frame *fp;
  1560. struct fcoe_port *port;
  1561. struct fcoe_hdr *hp;
  1562. fr = fcoe_dev_from_skb(skb);
  1563. lport = fr->fr_dev;
  1564. if (unlikely(!lport)) {
  1565. if (skb->destructor != fcoe_percpu_flush_done)
  1566. FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb");
  1567. kfree_skb(skb);
  1568. return;
  1569. }
  1570. FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d "
  1571. "head:%p data:%p tail:%p end:%p sum:%d dev:%s",
  1572. skb->len, skb->data_len,
  1573. skb->head, skb->data, skb_tail_pointer(skb),
  1574. skb_end_pointer(skb), skb->csum,
  1575. skb->dev ? skb->dev->name : "<NULL>");
  1576. port = lport_priv(lport);
  1577. skb_linearize(skb); /* check for skb_is_nonlinear is within skb_linearize */
  1578. /*
  1579. * Frame length checks and setting up the header pointers
  1580. * was done in fcoe_rcv already.
  1581. */
  1582. hp = (struct fcoe_hdr *) skb_network_header(skb);
  1583. stats = per_cpu_ptr(lport->stats, get_cpu());
  1584. if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
  1585. if (stats->ErrorFrames < 5)
  1586. printk(KERN_WARNING "fcoe: FCoE version "
  1587. "mismatch: The frame has "
  1588. "version %x, but the "
  1589. "initiator supports version "
  1590. "%x\n", FC_FCOE_DECAPS_VER(hp),
  1591. FC_FCOE_VER);
  1592. goto drop;
  1593. }
  1594. skb_pull(skb, sizeof(struct fcoe_hdr));
  1595. fr_len = skb->len - sizeof(struct fcoe_crc_eof);
  1596. stats->RxFrames++;
  1597. stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
  1598. fp = (struct fc_frame *)skb;
  1599. fc_frame_init(fp);
  1600. fr_dev(fp) = lport;
  1601. fr_sof(fp) = hp->fcoe_sof;
  1602. /* Copy out the CRC and EOF trailer for access */
  1603. if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof)))
  1604. goto drop;
  1605. fr_eof(fp) = crc_eof.fcoe_eof;
  1606. fr_crc(fp) = crc_eof.fcoe_crc32;
  1607. if (pskb_trim(skb, fr_len))
  1608. goto drop;
  1609. if (!fcoe_filter_frames(lport, fp)) {
  1610. put_cpu();
  1611. fc_exch_recv(lport, fp);
  1612. return;
  1613. }
  1614. drop:
  1615. stats->ErrorFrames++;
  1616. put_cpu();
  1617. kfree_skb(skb);
  1618. }
  1619. /**
  1620. * fcoe_percpu_receive_thread() - The per-CPU packet receive thread
  1621. * @arg: The per-CPU context
  1622. *
  1623. * Return: 0 for success
  1624. */
  1625. static int fcoe_percpu_receive_thread(void *arg)
  1626. {
  1627. struct fcoe_percpu_s *p = arg;
  1628. struct sk_buff *skb;
  1629. struct sk_buff_head tmp;
  1630. skb_queue_head_init(&tmp);
  1631. set_user_nice(current, -20);
  1632. retry:
  1633. while (!kthread_should_stop()) {
  1634. spin_lock_bh(&p->fcoe_rx_list.lock);
  1635. skb_queue_splice_init(&p->fcoe_rx_list, &tmp);
  1636. if (!skb_queue_len(&tmp)) {
  1637. set_current_state(TASK_INTERRUPTIBLE);
  1638. spin_unlock_bh(&p->fcoe_rx_list.lock);
  1639. schedule();
  1640. set_current_state(TASK_RUNNING);
  1641. goto retry;
  1642. }
  1643. spin_unlock_bh(&p->fcoe_rx_list.lock);
  1644. while ((skb = __skb_dequeue(&tmp)) != NULL)
  1645. fcoe_recv_frame(skb);
  1646. }
  1647. return 0;
  1648. }
  1649. /**
  1650. * fcoe_dev_setup() - Setup the link change notification interface
  1651. */
  1652. static void fcoe_dev_setup(void)
  1653. {
  1654. register_dcbevent_notifier(&dcb_notifier);
  1655. register_netdevice_notifier(&fcoe_notifier);
  1656. }
  1657. /**
  1658. * fcoe_dev_cleanup() - Cleanup the link change notification interface
  1659. */
  1660. static void fcoe_dev_cleanup(void)
  1661. {
  1662. unregister_dcbevent_notifier(&dcb_notifier);
  1663. unregister_netdevice_notifier(&fcoe_notifier);
  1664. }
  1665. static struct fcoe_interface *
  1666. fcoe_hostlist_lookup_realdev_port(struct net_device *netdev)
  1667. {
  1668. struct fcoe_interface *fcoe;
  1669. struct net_device *real_dev;
  1670. list_for_each_entry(fcoe, &fcoe_hostlist, list) {
  1671. if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
  1672. real_dev = vlan_dev_real_dev(fcoe->netdev);
  1673. else
  1674. real_dev = fcoe->netdev;
  1675. if (netdev == real_dev)
  1676. return fcoe;
  1677. }
  1678. return NULL;
  1679. }
  1680. static int fcoe_dcb_app_notification(struct notifier_block *notifier,
  1681. ulong event, void *ptr)
  1682. {
  1683. struct dcb_app_type *entry = ptr;
  1684. struct fcoe_ctlr *ctlr;
  1685. struct fcoe_interface *fcoe;
  1686. struct net_device *netdev;
  1687. int prio;
  1688. if (entry->app.selector != DCB_APP_IDTYPE_ETHTYPE)
  1689. return NOTIFY_OK;
  1690. netdev = dev_get_by_index(&init_net, entry->ifindex);
  1691. if (!netdev)
  1692. return NOTIFY_OK;
  1693. fcoe = fcoe_hostlist_lookup_realdev_port(netdev);
  1694. dev_put(netdev);
  1695. if (!fcoe)
  1696. return NOTIFY_OK;
  1697. ctlr = fcoe_to_ctlr(fcoe);
  1698. if (entry->dcbx & DCB_CAP_DCBX_VER_CEE)
  1699. prio = ffs(entry->app.priority) - 1;
  1700. else
  1701. prio = entry->app.priority;
  1702. if (prio < 0)
  1703. return NOTIFY_OK;
  1704. if (entry->app.protocol == ETH_P_FIP ||
  1705. entry->app.protocol == ETH_P_FCOE)
  1706. ctlr->priority = prio;
  1707. if (entry->app.protocol == ETH_P_FCOE)
  1708. fcoe->priority = prio;
  1709. return NOTIFY_OK;
  1710. }
  1711. /**
  1712. * fcoe_device_notification() - Handler for net device events
  1713. * @notifier: The context of the notification
  1714. * @event: The type of event
  1715. * @ptr: The net device that the event was on
  1716. *
  1717. * This function is called by the Ethernet driver in case of link change event.
  1718. *
  1719. * Returns: 0 for success
  1720. */
  1721. static int fcoe_device_notification(struct notifier_block *notifier,
  1722. ulong event, void *ptr)
  1723. {
  1724. struct fcoe_ctlr_device *cdev;
  1725. struct fc_lport *lport = NULL;
  1726. struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
  1727. struct fcoe_ctlr *ctlr;
  1728. struct fcoe_interface *fcoe;
  1729. struct fcoe_port *port;
  1730. struct fc_stats *stats;
  1731. u32 link_possible = 1;
  1732. u32 mfs;
  1733. int rc = NOTIFY_OK;
  1734. list_for_each_entry(fcoe, &fcoe_hostlist, list) {
  1735. if (fcoe->netdev == netdev) {
  1736. ctlr = fcoe_to_ctlr(fcoe);
  1737. lport = ctlr->lp;
  1738. break;
  1739. }
  1740. }
  1741. if (!lport) {
  1742. rc = NOTIFY_DONE;
  1743. goto out;
  1744. }
  1745. switch (event) {
  1746. case NETDEV_DOWN:
  1747. case NETDEV_GOING_DOWN:
  1748. link_possible = 0;
  1749. break;
  1750. case NETDEV_UP:
  1751. case NETDEV_CHANGE:
  1752. break;
  1753. case NETDEV_CHANGEMTU:
  1754. if (netdev->features & NETIF_F_FCOE_MTU)
  1755. break;
  1756. mfs = netdev->mtu - (sizeof(struct fcoe_hdr) +
  1757. sizeof(struct fcoe_crc_eof));
  1758. if (mfs >= FC_MIN_MAX_FRAME)
  1759. fc_set_mfs(lport, mfs);
  1760. break;
  1761. case NETDEV_REGISTER:
  1762. break;
  1763. case NETDEV_UNREGISTER:
  1764. list_del(&fcoe->list);
  1765. port = lport_priv(ctlr->lp);
  1766. queue_work(fcoe_wq, &port->destroy_work);
  1767. goto out;
  1768. break;
  1769. case NETDEV_FEAT_CHANGE:
  1770. fcoe_netdev_features_change(lport, netdev);
  1771. break;
  1772. default:
  1773. FCOE_NETDEV_DBG(netdev, "Unknown event %ld "
  1774. "from netdev netlink\n", event);
  1775. }
  1776. fcoe_link_speed_update(lport);
  1777. cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
  1778. if (link_possible && !fcoe_link_ok(lport)) {
  1779. switch (cdev->enabled) {
  1780. case FCOE_CTLR_DISABLED:
  1781. pr_info("Link up while interface is disabled.\n");
  1782. break;
  1783. case FCOE_CTLR_ENABLED:
  1784. case FCOE_CTLR_UNUSED:
  1785. fcoe_ctlr_link_up(ctlr);
  1786. };
  1787. } else if (fcoe_ctlr_link_down(ctlr)) {
  1788. switch (cdev->enabled) {
  1789. case FCOE_CTLR_DISABLED:
  1790. pr_info("Link down while interface is disabled.\n");
  1791. break;
  1792. case FCOE_CTLR_ENABLED:
  1793. case FCOE_CTLR_UNUSED:
  1794. stats = per_cpu_ptr(lport->stats, get_cpu());
  1795. stats->LinkFailureCount++;
  1796. put_cpu();
  1797. fcoe_clean_pending_queue(lport);
  1798. };
  1799. }
  1800. out:
  1801. return rc;
  1802. }
  1803. /**
  1804. * fcoe_disable() - Disables a FCoE interface
  1805. * @netdev : The net_device object the Ethernet interface to create on
  1806. *
  1807. * Called from fcoe transport.
  1808. *
  1809. * Returns: 0 for success
  1810. *
  1811. * Deprecated: use fcoe_ctlr_enabled()
  1812. */
  1813. static int fcoe_disable(struct net_device *netdev)
  1814. {
  1815. struct fcoe_ctlr *ctlr;
  1816. struct fcoe_interface *fcoe;
  1817. int rc = 0;
  1818. mutex_lock(&fcoe_config_mutex);
  1819. rtnl_lock();
  1820. fcoe = fcoe_hostlist_lookup_port(netdev);
  1821. rtnl_unlock();
  1822. if (fcoe) {
  1823. ctlr = fcoe_to_ctlr(fcoe);
  1824. fcoe_ctlr_link_down(ctlr);
  1825. fcoe_clean_pending_queue(ctlr->lp);
  1826. } else
  1827. rc = -ENODEV;
  1828. mutex_unlock(&fcoe_config_mutex);
  1829. return rc;
  1830. }
  1831. /**
  1832. * fcoe_enable() - Enables a FCoE interface
  1833. * @netdev : The net_device object the Ethernet interface to create on
  1834. *
  1835. * Called from fcoe transport.
  1836. *
  1837. * Returns: 0 for success
  1838. */
  1839. static int fcoe_enable(struct net_device *netdev)
  1840. {
  1841. struct fcoe_ctlr *ctlr;
  1842. struct fcoe_interface *fcoe;
  1843. int rc = 0;
  1844. mutex_lock(&fcoe_config_mutex);
  1845. rtnl_lock();
  1846. fcoe = fcoe_hostlist_lookup_port(netdev);
  1847. rtnl_unlock();
  1848. if (!fcoe) {
  1849. rc = -ENODEV;
  1850. goto out;
  1851. }
  1852. ctlr = fcoe_to_ctlr(fcoe);
  1853. if (!fcoe_link_ok(ctlr->lp))
  1854. fcoe_ctlr_link_up(ctlr);
  1855. out:
  1856. mutex_unlock(&fcoe_config_mutex);
  1857. return rc;
  1858. }
  1859. /**
  1860. * fcoe_ctlr_enabled() - Enable or disable an FCoE Controller
  1861. * @cdev: The FCoE Controller that is being enabled or disabled
  1862. *
  1863. * fcoe_sysfs will ensure that the state of 'enabled' has
  1864. * changed, so no checking is necessary here. This routine simply
  1865. * calls fcoe_enable or fcoe_disable, both of which are deprecated.
  1866. * When those routines are removed the functionality can be merged
  1867. * here.
  1868. */
  1869. static int fcoe_ctlr_enabled(struct fcoe_ctlr_device *cdev)
  1870. {
  1871. struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
  1872. struct fc_lport *lport = ctlr->lp;
  1873. struct net_device *netdev = fcoe_netdev(lport);
  1874. switch (cdev->enabled) {
  1875. case FCOE_CTLR_ENABLED:
  1876. return fcoe_enable(netdev);
  1877. case FCOE_CTLR_DISABLED:
  1878. return fcoe_disable(netdev);
  1879. case FCOE_CTLR_UNUSED:
  1880. default:
  1881. return -ENOTSUPP;
  1882. };
  1883. }
  1884. /**
  1885. * fcoe_destroy() - Destroy a FCoE interface
  1886. * @netdev : The net_device object the Ethernet interface to create on
  1887. *
  1888. * Called from fcoe transport
  1889. *
  1890. * Returns: 0 for success
  1891. */
  1892. static int fcoe_destroy(struct net_device *netdev)
  1893. {
  1894. struct fcoe_ctlr *ctlr;
  1895. struct fcoe_interface *fcoe;
  1896. struct fc_lport *lport;
  1897. struct fcoe_port *port;
  1898. int rc = 0;
  1899. mutex_lock(&fcoe_config_mutex);
  1900. rtnl_lock();
  1901. fcoe = fcoe_hostlist_lookup_port(netdev);
  1902. if (!fcoe) {
  1903. rc = -ENODEV;
  1904. goto out_nodev;
  1905. }
  1906. ctlr = fcoe_to_ctlr(fcoe);
  1907. lport = ctlr->lp;
  1908. port = lport_priv(lport);
  1909. list_del(&fcoe->list);
  1910. queue_work(fcoe_wq, &port->destroy_work);
  1911. out_nodev:
  1912. rtnl_unlock();
  1913. mutex_unlock(&fcoe_config_mutex);
  1914. return rc;
  1915. }
  1916. /**
  1917. * fcoe_destroy_work() - Destroy a FCoE port in a deferred work context
  1918. * @work: Handle to the FCoE port to be destroyed
  1919. */
  1920. static void fcoe_destroy_work(struct work_struct *work)
  1921. {
  1922. struct fcoe_ctlr_device *cdev;
  1923. struct fcoe_ctlr *ctlr;
  1924. struct fcoe_port *port;
  1925. struct fcoe_interface *fcoe;
  1926. struct Scsi_Host *shost;
  1927. struct fc_host_attrs *fc_host;
  1928. unsigned long flags;
  1929. struct fc_vport *vport;
  1930. struct fc_vport *next_vport;
  1931. port = container_of(work, struct fcoe_port, destroy_work);
  1932. shost = port->lport->host;
  1933. fc_host = shost_to_fc_host(shost);
  1934. /* Loop through all the vports and mark them for deletion */
  1935. spin_lock_irqsave(shost->host_lock, flags);
  1936. list_for_each_entry_safe(vport, next_vport, &fc_host->vports, peers) {
  1937. if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) {
  1938. continue;
  1939. } else {
  1940. vport->flags |= FC_VPORT_DELETING;
  1941. queue_work(fc_host_work_q(shost),
  1942. &vport->vport_delete_work);
  1943. }
  1944. }
  1945. spin_unlock_irqrestore(shost->host_lock, flags);
  1946. flush_workqueue(fc_host_work_q(shost));
  1947. mutex_lock(&fcoe_config_mutex);
  1948. fcoe = port->priv;
  1949. ctlr = fcoe_to_ctlr(fcoe);
  1950. cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
  1951. fcoe_if_destroy(port->lport);
  1952. fcoe_interface_cleanup(fcoe);
  1953. mutex_unlock(&fcoe_config_mutex);
  1954. fcoe_ctlr_device_delete(cdev);
  1955. }
  1956. /**
  1957. * fcoe_match() - Check if the FCoE is supported on the given netdevice
  1958. * @netdev : The net_device object the Ethernet interface to create on
  1959. *
  1960. * Called from fcoe transport.
  1961. *
  1962. * Returns: always returns true as this is the default FCoE transport,
  1963. * i.e., support all netdevs.
  1964. */
  1965. static bool fcoe_match(struct net_device *netdev)
  1966. {
  1967. return true;
  1968. }
  1969. /**
  1970. * fcoe_dcb_create() - Initialize DCB attributes and hooks
  1971. * @netdev: The net_device object of the L2 link that should be queried
  1972. * @port: The fcoe_port to bind FCoE APP priority with
  1973. * @
  1974. */
  1975. static void fcoe_dcb_create(struct fcoe_interface *fcoe)
  1976. {
  1977. #ifdef CONFIG_DCB
  1978. int dcbx;
  1979. u8 fup, up;
  1980. struct net_device *netdev = fcoe->realdev;
  1981. struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
  1982. struct dcb_app app = {
  1983. .priority = 0,
  1984. .protocol = ETH_P_FCOE
  1985. };
  1986. /* setup DCB priority attributes. */
  1987. if (netdev && netdev->dcbnl_ops && netdev->dcbnl_ops->getdcbx) {
  1988. dcbx = netdev->dcbnl_ops->getdcbx(netdev);
  1989. if (dcbx & DCB_CAP_DCBX_VER_IEEE) {
  1990. app.selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE;
  1991. up = dcb_ieee_getapp_mask(netdev, &app);
  1992. app.protocol = ETH_P_FIP;
  1993. fup = dcb_ieee_getapp_mask(netdev, &app);
  1994. } else {
  1995. app.selector = DCB_APP_IDTYPE_ETHTYPE;
  1996. up = dcb_getapp(netdev, &app);
  1997. app.protocol = ETH_P_FIP;
  1998. fup = dcb_getapp(netdev, &app);
  1999. }
  2000. fcoe->priority = ffs(up) ? ffs(up) - 1 : 0;
  2001. ctlr->priority = ffs(fup) ? ffs(fup) - 1 : fcoe->priority;
  2002. }
  2003. #endif
  2004. }
  2005. enum fcoe_create_link_state {
  2006. FCOE_CREATE_LINK_DOWN,
  2007. FCOE_CREATE_LINK_UP,
  2008. };
  2009. /**
  2010. * _fcoe_create() - (internal) Create a fcoe interface
  2011. * @netdev : The net_device object the Ethernet interface to create on
  2012. * @fip_mode: The FIP mode for this creation
  2013. * @link_state: The ctlr link state on creation
  2014. *
  2015. * Called from either the libfcoe 'create' module parameter
  2016. * via fcoe_create or from fcoe_syfs's ctlr_create file.
  2017. *
  2018. * libfcoe's 'create' module parameter is deprecated so some
  2019. * consolidation of code can be done when that interface is
  2020. * removed.
  2021. */
  2022. static int _fcoe_create(struct net_device *netdev, enum fip_state fip_mode,
  2023. enum fcoe_create_link_state link_state)
  2024. {
  2025. int rc = 0;
  2026. struct fcoe_ctlr_device *ctlr_dev;
  2027. struct fcoe_ctlr *ctlr;
  2028. struct fcoe_interface *fcoe;
  2029. struct fc_lport *lport;
  2030. mutex_lock(&fcoe_config_mutex);
  2031. rtnl_lock();
  2032. /* look for existing lport */
  2033. if (fcoe_hostlist_lookup(netdev)) {
  2034. rc = -EEXIST;
  2035. goto out_nodev;
  2036. }
  2037. fcoe = fcoe_interface_create(netdev, fip_mode);
  2038. if (IS_ERR(fcoe)) {
  2039. rc = PTR_ERR(fcoe);
  2040. goto out_nodev;
  2041. }
  2042. ctlr = fcoe_to_ctlr(fcoe);
  2043. ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
  2044. lport = fcoe_if_create(fcoe, &ctlr_dev->dev, 0);
  2045. if (IS_ERR(lport)) {
  2046. printk(KERN_ERR "fcoe: Failed to create interface (%s)\n",
  2047. netdev->name);
  2048. rc = -EIO;
  2049. rtnl_unlock();
  2050. fcoe_interface_cleanup(fcoe);
  2051. mutex_unlock(&fcoe_config_mutex);
  2052. fcoe_ctlr_device_delete(ctlr_dev);
  2053. goto out;
  2054. }
  2055. /* Make this the "master" N_Port */
  2056. ctlr->lp = lport;
  2057. /* setup DCB priority attributes. */
  2058. fcoe_dcb_create(fcoe);
  2059. /* start FIP Discovery and FLOGI */
  2060. lport->boot_time = jiffies;
  2061. fc_fabric_login(lport);
  2062. /*
  2063. * If the fcoe_ctlr_device is to be set to DISABLED
  2064. * it must be done after the lport is added to the
  2065. * hostlist, but before the rtnl_lock is released.
  2066. * This is because the rtnl_lock protects the
  2067. * hostlist that fcoe_device_notification uses. If
  2068. * the FCoE Controller is intended to be created
  2069. * DISABLED then 'enabled' needs to be considered
  2070. * handling link events. 'enabled' must be set
  2071. * before the lport can be found in the hostlist
  2072. * when a link up event is received.
  2073. */
  2074. if (link_state == FCOE_CREATE_LINK_UP)
  2075. ctlr_dev->enabled = FCOE_CTLR_ENABLED;
  2076. else
  2077. ctlr_dev->enabled = FCOE_CTLR_DISABLED;
  2078. if (link_state == FCOE_CREATE_LINK_UP &&
  2079. !fcoe_link_ok(lport)) {
  2080. rtnl_unlock();
  2081. fcoe_ctlr_link_up(ctlr);
  2082. mutex_unlock(&fcoe_config_mutex);
  2083. return rc;
  2084. }
  2085. out_nodev:
  2086. rtnl_unlock();
  2087. mutex_unlock(&fcoe_config_mutex);
  2088. out:
  2089. return rc;
  2090. }
  2091. /**
  2092. * fcoe_create() - Create a fcoe interface
  2093. * @netdev : The net_device object the Ethernet interface to create on
  2094. * @fip_mode: The FIP mode for this creation
  2095. *
  2096. * Called from fcoe transport
  2097. *
  2098. * Returns: 0 for success
  2099. */
  2100. static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode)
  2101. {
  2102. return _fcoe_create(netdev, fip_mode, FCOE_CREATE_LINK_UP);
  2103. }
  2104. /**
  2105. * fcoe_ctlr_alloc() - Allocate a fcoe interface from fcoe_sysfs
  2106. * @netdev: The net_device to be used by the allocated FCoE Controller
  2107. *
  2108. * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
  2109. * in a link_down state. The allows the user an opportunity to configure
  2110. * the FCoE Controller from sysfs before enabling the FCoE Controller.
  2111. *
  2112. * Creating in with this routine starts the FCoE Controller in Fabric
  2113. * mode. The user can change to VN2VN or another mode before enabling.
  2114. */
  2115. static int fcoe_ctlr_alloc(struct net_device *netdev)
  2116. {
  2117. return _fcoe_create(netdev, FIP_MODE_FABRIC,
  2118. FCOE_CREATE_LINK_DOWN);
  2119. }
  2120. /**
  2121. * fcoe_link_ok() - Check if the link is OK for a local port
  2122. * @lport: The local port to check link on
  2123. *
  2124. * Returns: 0 if link is UP and OK, -1 if not
  2125. *
  2126. */
  2127. static int fcoe_link_ok(struct fc_lport *lport)
  2128. {
  2129. struct net_device *netdev = fcoe_netdev(lport);
  2130. if (netif_oper_up(netdev))
  2131. return 0;
  2132. return -1;
  2133. }
  2134. /**
  2135. * fcoe_percpu_clean() - Clear all pending skbs for an local port
  2136. * @lport: The local port whose skbs are to be cleared
  2137. *
  2138. * Must be called with fcoe_create_mutex held to single-thread completion.
  2139. *
  2140. * This flushes the pending skbs by adding a new skb to each queue and
  2141. * waiting until they are all freed. This assures us that not only are
  2142. * there no packets that will be handled by the lport, but also that any
  2143. * threads already handling packet have returned.
  2144. */
  2145. static void fcoe_percpu_clean(struct fc_lport *lport)
  2146. {
  2147. struct fcoe_percpu_s *pp;
  2148. struct sk_buff *skb;
  2149. unsigned int cpu;
  2150. for_each_possible_cpu(cpu) {
  2151. pp = &per_cpu(fcoe_percpu, cpu);
  2152. if (!pp->thread || !cpu_online(cpu))
  2153. continue;
  2154. skb = dev_alloc_skb(0);
  2155. if (!skb)
  2156. continue;
  2157. skb->destructor = fcoe_percpu_flush_done;
  2158. spin_lock_bh(&pp->fcoe_rx_list.lock);
  2159. __skb_queue_tail(&pp->fcoe_rx_list, skb);
  2160. if (pp->fcoe_rx_list.qlen == 1)
  2161. wake_up_process(pp->thread);
  2162. spin_unlock_bh(&pp->fcoe_rx_list.lock);
  2163. wait_for_completion(&fcoe_flush_completion);
  2164. }
  2165. }
  2166. /**
  2167. * fcoe_reset() - Reset a local port
  2168. * @shost: The SCSI host associated with the local port to be reset
  2169. *
  2170. * Returns: Always 0 (return value required by FC transport template)
  2171. */
  2172. static int fcoe_reset(struct Scsi_Host *shost)
  2173. {
  2174. struct fc_lport *lport = shost_priv(shost);
  2175. struct fcoe_port *port = lport_priv(lport);
  2176. struct fcoe_interface *fcoe = port->priv;
  2177. struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
  2178. struct fcoe_ctlr_device *cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
  2179. fcoe_ctlr_link_down(ctlr);
  2180. fcoe_clean_pending_queue(ctlr->lp);
  2181. if (cdev->enabled != FCOE_CTLR_DISABLED &&
  2182. !fcoe_link_ok(ctlr->lp))
  2183. fcoe_ctlr_link_up(ctlr);
  2184. return 0;
  2185. }
  2186. /**
  2187. * fcoe_hostlist_lookup_port() - Find the FCoE interface associated with a net device
  2188. * @netdev: The net device used as a key
  2189. *
  2190. * Locking: Must be called with the RNL mutex held.
  2191. *
  2192. * Returns: NULL or the FCoE interface
  2193. */
  2194. static struct fcoe_interface *
  2195. fcoe_hostlist_lookup_port(const struct net_device *netdev)
  2196. {
  2197. struct fcoe_interface *fcoe;
  2198. list_for_each_entry(fcoe, &fcoe_hostlist, list) {
  2199. if (fcoe->netdev == netdev)
  2200. return fcoe;
  2201. }
  2202. return NULL;
  2203. }
  2204. /**
  2205. * fcoe_hostlist_lookup() - Find the local port associated with a
  2206. * given net device
  2207. * @netdev: The netdevice used as a key
  2208. *
  2209. * Locking: Must be called with the RTNL mutex held
  2210. *
  2211. * Returns: NULL or the local port
  2212. */
  2213. static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
  2214. {
  2215. struct fcoe_ctlr *ctlr;
  2216. struct fcoe_interface *fcoe;
  2217. fcoe = fcoe_hostlist_lookup_port(netdev);
  2218. ctlr = fcoe_to_ctlr(fcoe);
  2219. return (fcoe) ? ctlr->lp : NULL;
  2220. }
  2221. /**
  2222. * fcoe_hostlist_add() - Add the FCoE interface identified by a local
  2223. * port to the hostlist
  2224. * @lport: The local port that identifies the FCoE interface to be added
  2225. *
  2226. * Locking: must be called with the RTNL mutex held
  2227. *
  2228. * Returns: 0 for success
  2229. */
  2230. static int fcoe_hostlist_add(const struct fc_lport *lport)
  2231. {
  2232. struct fcoe_interface *fcoe;
  2233. struct fcoe_port *port;
  2234. fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport));
  2235. if (!fcoe) {
  2236. port = lport_priv(lport);
  2237. fcoe = port->priv;
  2238. list_add_tail(&fcoe->list, &fcoe_hostlist);
  2239. }
  2240. return 0;
  2241. }
  2242. /**
  2243. * fcoe_hostlist_del() - Remove the FCoE interface identified by a local
  2244. * port to the hostlist
  2245. * @lport: The local port that identifies the FCoE interface to be added
  2246. *
  2247. * Locking: must be called with the RTNL mutex held
  2248. *
  2249. */
  2250. static void fcoe_hostlist_del(const struct fc_lport *lport)
  2251. {
  2252. struct fcoe_interface *fcoe;
  2253. struct fcoe_port *port;
  2254. port = lport_priv(lport);
  2255. fcoe = port->priv;
  2256. list_del(&fcoe->list);
  2257. return;
  2258. }
  2259. static struct fcoe_transport fcoe_sw_transport = {
  2260. .name = {FCOE_TRANSPORT_DEFAULT},
  2261. .attached = false,
  2262. .list = LIST_HEAD_INIT(fcoe_sw_transport.list),
  2263. .match = fcoe_match,
  2264. .alloc = fcoe_ctlr_alloc,
  2265. .create = fcoe_create,
  2266. .destroy = fcoe_destroy,
  2267. .enable = fcoe_enable,
  2268. .disable = fcoe_disable,
  2269. };
  2270. /**
  2271. * fcoe_init() - Initialize fcoe.ko
  2272. *
  2273. * Returns: 0 on success, or a negative value on failure
  2274. */
  2275. static int __init fcoe_init(void)
  2276. {
  2277. struct fcoe_percpu_s *p;
  2278. unsigned int cpu;
  2279. int rc = 0;
  2280. fcoe_wq = alloc_workqueue("fcoe", 0, 0);
  2281. if (!fcoe_wq)
  2282. return -ENOMEM;
  2283. /* register as a fcoe transport */
  2284. rc = fcoe_transport_attach(&fcoe_sw_transport);
  2285. if (rc) {
  2286. printk(KERN_ERR "failed to register an fcoe transport, check "
  2287. "if libfcoe is loaded\n");
  2288. return rc;
  2289. }
  2290. mutex_lock(&fcoe_config_mutex);
  2291. for_each_possible_cpu(cpu) {
  2292. p = &per_cpu(fcoe_percpu, cpu);
  2293. skb_queue_head_init(&p->fcoe_rx_list);
  2294. }
  2295. for_each_online_cpu(cpu)
  2296. fcoe_percpu_thread_create(cpu);
  2297. /* Initialize per CPU interrupt thread */
  2298. rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
  2299. if (rc)
  2300. goto out_free;
  2301. /* Setup link change notification */
  2302. fcoe_dev_setup();
  2303. rc = fcoe_if_init();
  2304. if (rc)
  2305. goto out_free;
  2306. mutex_unlock(&fcoe_config_mutex);
  2307. return 0;
  2308. out_free:
  2309. for_each_online_cpu(cpu) {
  2310. fcoe_percpu_thread_destroy(cpu);
  2311. }
  2312. mutex_unlock(&fcoe_config_mutex);
  2313. destroy_workqueue(fcoe_wq);
  2314. return rc;
  2315. }
  2316. module_init(fcoe_init);
  2317. /**
  2318. * fcoe_exit() - Clean up fcoe.ko
  2319. *
  2320. * Returns: 0 on success or a negative value on failure
  2321. */
  2322. static void __exit fcoe_exit(void)
  2323. {
  2324. struct fcoe_interface *fcoe, *tmp;
  2325. struct fcoe_ctlr *ctlr;
  2326. struct fcoe_port *port;
  2327. unsigned int cpu;
  2328. mutex_lock(&fcoe_config_mutex);
  2329. fcoe_dev_cleanup();
  2330. /* releases the associated fcoe hosts */
  2331. rtnl_lock();
  2332. list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) {
  2333. ctlr = fcoe_to_ctlr(fcoe);
  2334. port = lport_priv(ctlr->lp);
  2335. fcoe_hostlist_del(port->lport);
  2336. queue_work(fcoe_wq, &port->destroy_work);
  2337. }
  2338. rtnl_unlock();
  2339. unregister_hotcpu_notifier(&fcoe_cpu_notifier);
  2340. for_each_online_cpu(cpu)
  2341. fcoe_percpu_thread_destroy(cpu);
  2342. mutex_unlock(&fcoe_config_mutex);
  2343. /*
  2344. * destroy_work's may be chained but destroy_workqueue()
  2345. * can take care of them. Just kill the fcoe_wq.
  2346. */
  2347. destroy_workqueue(fcoe_wq);
  2348. /*
  2349. * Detaching from the scsi transport must happen after all
  2350. * destroys are done on the fcoe_wq. destroy_workqueue will
  2351. * enusre the fcoe_wq is flushed.
  2352. */
  2353. fcoe_if_exit();
  2354. /* detach from fcoe transport */
  2355. fcoe_transport_detach(&fcoe_sw_transport);
  2356. }
  2357. module_exit(fcoe_exit);
  2358. /**
  2359. * fcoe_flogi_resp() - FCoE specific FLOGI and FDISC response handler
  2360. * @seq: active sequence in the FLOGI or FDISC exchange
  2361. * @fp: response frame, or error encoded in a pointer (timeout)
  2362. * @arg: pointer the the fcoe_ctlr structure
  2363. *
  2364. * This handles MAC address management for FCoE, then passes control on to
  2365. * the libfc FLOGI response handler.
  2366. */
  2367. static void fcoe_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
  2368. {
  2369. struct fcoe_ctlr *fip = arg;
  2370. struct fc_exch *exch = fc_seq_exch(seq);
  2371. struct fc_lport *lport = exch->lp;
  2372. u8 *mac;
  2373. if (IS_ERR(fp))
  2374. goto done;
  2375. mac = fr_cb(fp)->granted_mac;
  2376. /* pre-FIP */
  2377. if (is_zero_ether_addr(mac))
  2378. fcoe_ctlr_recv_flogi(fip, lport, fp);
  2379. if (!is_zero_ether_addr(mac))
  2380. fcoe_update_src_mac(lport, mac);
  2381. done:
  2382. fc_lport_flogi_resp(seq, fp, lport);
  2383. }
  2384. /**
  2385. * fcoe_logo_resp() - FCoE specific LOGO response handler
  2386. * @seq: active sequence in the LOGO exchange
  2387. * @fp: response frame, or error encoded in a pointer (timeout)
  2388. * @arg: pointer the the fcoe_ctlr structure
  2389. *
  2390. * This handles MAC address management for FCoE, then passes control on to
  2391. * the libfc LOGO response handler.
  2392. */
  2393. static void fcoe_logo_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
  2394. {
  2395. struct fc_lport *lport = arg;
  2396. static u8 zero_mac[ETH_ALEN] = { 0 };
  2397. if (!IS_ERR(fp))
  2398. fcoe_update_src_mac(lport, zero_mac);
  2399. fc_lport_logo_resp(seq, fp, lport);
  2400. }
  2401. /**
  2402. * fcoe_elsct_send - FCoE specific ELS handler
  2403. *
  2404. * This does special case handling of FIP encapsualted ELS exchanges for FCoE,
  2405. * using FCoE specific response handlers and passing the FIP controller as
  2406. * the argument (the lport is still available from the exchange).
  2407. *
  2408. * Most of the work here is just handed off to the libfc routine.
  2409. */
  2410. static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport, u32 did,
  2411. struct fc_frame *fp, unsigned int op,
  2412. void (*resp)(struct fc_seq *,
  2413. struct fc_frame *,
  2414. void *),
  2415. void *arg, u32 timeout)
  2416. {
  2417. struct fcoe_port *port = lport_priv(lport);
  2418. struct fcoe_interface *fcoe = port->priv;
  2419. struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
  2420. struct fc_frame_header *fh = fc_frame_header_get(fp);
  2421. switch (op) {
  2422. case ELS_FLOGI:
  2423. case ELS_FDISC:
  2424. if (lport->point_to_multipoint)
  2425. break;
  2426. return fc_elsct_send(lport, did, fp, op, fcoe_flogi_resp,
  2427. fip, timeout);
  2428. case ELS_LOGO:
  2429. /* only hook onto fabric logouts, not port logouts */
  2430. if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI)
  2431. break;
  2432. return fc_elsct_send(lport, did, fp, op, fcoe_logo_resp,
  2433. lport, timeout);
  2434. }
  2435. return fc_elsct_send(lport, did, fp, op, resp, arg, timeout);
  2436. }
  2437. /**
  2438. * fcoe_vport_create() - create an fc_host/scsi_host for a vport
  2439. * @vport: fc_vport object to create a new fc_host for
  2440. * @disabled: start the new fc_host in a disabled state by default?
  2441. *
  2442. * Returns: 0 for success
  2443. */
  2444. static int fcoe_vport_create(struct fc_vport *vport, bool disabled)
  2445. {
  2446. struct Scsi_Host *shost = vport_to_shost(vport);
  2447. struct fc_lport *n_port = shost_priv(shost);
  2448. struct fcoe_port *port = lport_priv(n_port);
  2449. struct fcoe_interface *fcoe = port->priv;
  2450. struct net_device *netdev = fcoe->netdev;
  2451. struct fc_lport *vn_port;
  2452. int rc;
  2453. char buf[32];
  2454. rc = fcoe_validate_vport_create(vport);
  2455. if (rc) {
  2456. fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
  2457. printk(KERN_ERR "fcoe: Failed to create vport, "
  2458. "WWPN (0x%s) already exists\n",
  2459. buf);
  2460. return rc;
  2461. }
  2462. mutex_lock(&fcoe_config_mutex);
  2463. rtnl_lock();
  2464. vn_port = fcoe_if_create(fcoe, &vport->dev, 1);
  2465. rtnl_unlock();
  2466. mutex_unlock(&fcoe_config_mutex);
  2467. if (IS_ERR(vn_port)) {
  2468. printk(KERN_ERR "fcoe: fcoe_vport_create(%s) failed\n",
  2469. netdev->name);
  2470. return -EIO;
  2471. }
  2472. if (disabled) {
  2473. fc_vport_set_state(vport, FC_VPORT_DISABLED);
  2474. } else {
  2475. vn_port->boot_time = jiffies;
  2476. fc_fabric_login(vn_port);
  2477. fc_vport_setlink(vn_port);
  2478. }
  2479. return 0;
  2480. }
  2481. /**
  2482. * fcoe_vport_destroy() - destroy the fc_host/scsi_host for a vport
  2483. * @vport: fc_vport object that is being destroyed
  2484. *
  2485. * Returns: 0 for success
  2486. */
  2487. static int fcoe_vport_destroy(struct fc_vport *vport)
  2488. {
  2489. struct Scsi_Host *shost = vport_to_shost(vport);
  2490. struct fc_lport *n_port = shost_priv(shost);
  2491. struct fc_lport *vn_port = vport->dd_data;
  2492. mutex_lock(&n_port->lp_mutex);
  2493. list_del(&vn_port->list);
  2494. mutex_unlock(&n_port->lp_mutex);
  2495. mutex_lock(&fcoe_config_mutex);
  2496. fcoe_if_destroy(vn_port);
  2497. mutex_unlock(&fcoe_config_mutex);
  2498. return 0;
  2499. }
  2500. /**
  2501. * fcoe_vport_disable() - change vport state
  2502. * @vport: vport to bring online/offline
  2503. * @disable: should the vport be disabled?
  2504. */
  2505. static int fcoe_vport_disable(struct fc_vport *vport, bool disable)
  2506. {
  2507. struct fc_lport *lport = vport->dd_data;
  2508. if (disable) {
  2509. fc_vport_set_state(vport, FC_VPORT_DISABLED);
  2510. fc_fabric_logoff(lport);
  2511. } else {
  2512. lport->boot_time = jiffies;
  2513. fc_fabric_login(lport);
  2514. fc_vport_setlink(lport);
  2515. }
  2516. return 0;
  2517. }
  2518. /**
  2519. * fcoe_vport_set_symbolic_name() - append vport string to symbolic name
  2520. * @vport: fc_vport with a new symbolic name string
  2521. *
  2522. * After generating a new symbolic name string, a new RSPN_ID request is
  2523. * sent to the name server. There is no response handler, so if it fails
  2524. * for some reason it will not be retried.
  2525. */
  2526. static void fcoe_set_vport_symbolic_name(struct fc_vport *vport)
  2527. {
  2528. struct fc_lport *lport = vport->dd_data;
  2529. struct fc_frame *fp;
  2530. size_t len;
  2531. snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE,
  2532. "%s v%s over %s : %s", FCOE_NAME, FCOE_VERSION,
  2533. fcoe_netdev(lport)->name, vport->symbolic_name);
  2534. if (lport->state != LPORT_ST_READY)
  2535. return;
  2536. len = strnlen(fc_host_symbolic_name(lport->host), 255);
  2537. fp = fc_frame_alloc(lport,
  2538. sizeof(struct fc_ct_hdr) +
  2539. sizeof(struct fc_ns_rspn) + len);
  2540. if (!fp)
  2541. return;
  2542. lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSPN_ID,
  2543. NULL, NULL, 3 * lport->r_a_tov);
  2544. }
  2545. static void fcoe_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
  2546. {
  2547. struct fcoe_ctlr_device *ctlr_dev =
  2548. fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
  2549. struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
  2550. struct fcoe_interface *fcoe = fcoe_ctlr_priv(ctlr);
  2551. fcf_dev->vlan_id = vlan_dev_vlan_id(fcoe->netdev);
  2552. }
  2553. /**
  2554. * fcoe_set_port_id() - Callback from libfc when Port_ID is set.
  2555. * @lport: the local port
  2556. * @port_id: the port ID
  2557. * @fp: the received frame, if any, that caused the port_id to be set.
  2558. *
  2559. * This routine handles the case where we received a FLOGI and are
  2560. * entering point-to-point mode. We need to call fcoe_ctlr_recv_flogi()
  2561. * so it can set the non-mapped mode and gateway address.
  2562. *
  2563. * The FLOGI LS_ACC is handled by fcoe_flogi_resp().
  2564. */
  2565. static void fcoe_set_port_id(struct fc_lport *lport,
  2566. u32 port_id, struct fc_frame *fp)
  2567. {
  2568. struct fcoe_port *port = lport_priv(lport);
  2569. struct fcoe_interface *fcoe = port->priv;
  2570. struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
  2571. if (fp && fc_frame_payload_op(fp) == ELS_FLOGI)
  2572. fcoe_ctlr_recv_flogi(ctlr, lport, fp);
  2573. }