fcoe.c 76 KB

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