fcoe.c 77 KB

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