fcoe.c 75 KB

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