fcoe.c 76 KB

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