fcoe.c 77 KB

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