fcoe.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365
  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/version.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/ethtool.h>
  25. #include <linux/if_ether.h>
  26. #include <linux/if_vlan.h>
  27. #include <linux/crc32.h>
  28. #include <linux/cpu.h>
  29. #include <linux/fs.h>
  30. #include <linux/sysfs.h>
  31. #include <linux/ctype.h>
  32. #include <scsi/scsi_tcq.h>
  33. #include <scsi/scsicam.h>
  34. #include <scsi/scsi_transport.h>
  35. #include <scsi/scsi_transport_fc.h>
  36. #include <net/rtnetlink.h>
  37. #include <scsi/fc/fc_encaps.h>
  38. #include <scsi/fc/fc_fip.h>
  39. #include <scsi/libfc.h>
  40. #include <scsi/fc_frame.h>
  41. #include <scsi/libfcoe.h>
  42. #include "fcoe.h"
  43. MODULE_AUTHOR("Open-FCoE.org");
  44. MODULE_DESCRIPTION("FCoE");
  45. MODULE_LICENSE("GPL v2");
  46. /* Performance tuning parameters for fcoe */
  47. static unsigned int fcoe_ddp_min;
  48. module_param_named(ddp_min, fcoe_ddp_min, uint, S_IRUGO | S_IWUSR);
  49. MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for " \
  50. "Direct Data Placement (DDP).");
  51. DEFINE_MUTEX(fcoe_config_mutex);
  52. /* fcoe_percpu_clean completion. Waiter protected by fcoe_create_mutex */
  53. static DECLARE_COMPLETION(fcoe_flush_completion);
  54. /* fcoe host list */
  55. /* must only by accessed under the RTNL mutex */
  56. LIST_HEAD(fcoe_hostlist);
  57. DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
  58. /* Function Prototypes */
  59. static int fcoe_reset(struct Scsi_Host *shost);
  60. static int fcoe_xmit(struct fc_lport *, struct fc_frame *);
  61. static int fcoe_rcv(struct sk_buff *, struct net_device *,
  62. struct packet_type *, struct net_device *);
  63. static int fcoe_percpu_receive_thread(void *arg);
  64. static void fcoe_clean_pending_queue(struct fc_lport *lp);
  65. static void fcoe_percpu_clean(struct fc_lport *lp);
  66. static int fcoe_link_ok(struct fc_lport *lp);
  67. static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
  68. static int fcoe_hostlist_add(const struct fc_lport *);
  69. static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *);
  70. static int fcoe_device_notification(struct notifier_block *, ulong, void *);
  71. static void fcoe_dev_setup(void);
  72. static void fcoe_dev_cleanup(void);
  73. static struct fcoe_interface *
  74. fcoe_hostlist_lookup_port(const struct net_device *dev);
  75. /* notification function from net device */
  76. static struct notifier_block fcoe_notifier = {
  77. .notifier_call = fcoe_device_notification,
  78. };
  79. static struct scsi_transport_template *fcoe_transport_template;
  80. static struct scsi_transport_template *fcoe_vport_transport_template;
  81. static int fcoe_vport_destroy(struct fc_vport *vport);
  82. static int fcoe_vport_create(struct fc_vport *vport, bool disabled);
  83. static int fcoe_vport_disable(struct fc_vport *vport, bool disable);
  84. static void fcoe_set_vport_symbolic_name(struct fc_vport *vport);
  85. struct fc_function_template fcoe_transport_function = {
  86. .show_host_node_name = 1,
  87. .show_host_port_name = 1,
  88. .show_host_supported_classes = 1,
  89. .show_host_supported_fc4s = 1,
  90. .show_host_active_fc4s = 1,
  91. .show_host_maxframe_size = 1,
  92. .show_host_port_id = 1,
  93. .show_host_supported_speeds = 1,
  94. .get_host_speed = fc_get_host_speed,
  95. .show_host_speed = 1,
  96. .show_host_port_type = 1,
  97. .get_host_port_state = fc_get_host_port_state,
  98. .show_host_port_state = 1,
  99. .show_host_symbolic_name = 1,
  100. .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
  101. .show_rport_maxframe_size = 1,
  102. .show_rport_supported_classes = 1,
  103. .show_host_fabric_name = 1,
  104. .show_starget_node_name = 1,
  105. .show_starget_port_name = 1,
  106. .show_starget_port_id = 1,
  107. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  108. .show_rport_dev_loss_tmo = 1,
  109. .get_fc_host_stats = fc_get_host_stats,
  110. .issue_fc_host_lip = fcoe_reset,
  111. .terminate_rport_io = fc_rport_terminate_io,
  112. .vport_create = fcoe_vport_create,
  113. .vport_delete = fcoe_vport_destroy,
  114. .vport_disable = fcoe_vport_disable,
  115. .set_vport_symbolic_name = fcoe_set_vport_symbolic_name,
  116. .bsg_request = fc_lport_bsg_request,
  117. };
  118. struct fc_function_template fcoe_vport_transport_function = {
  119. .show_host_node_name = 1,
  120. .show_host_port_name = 1,
  121. .show_host_supported_classes = 1,
  122. .show_host_supported_fc4s = 1,
  123. .show_host_active_fc4s = 1,
  124. .show_host_maxframe_size = 1,
  125. .show_host_port_id = 1,
  126. .show_host_supported_speeds = 1,
  127. .get_host_speed = fc_get_host_speed,
  128. .show_host_speed = 1,
  129. .show_host_port_type = 1,
  130. .get_host_port_state = fc_get_host_port_state,
  131. .show_host_port_state = 1,
  132. .show_host_symbolic_name = 1,
  133. .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
  134. .show_rport_maxframe_size = 1,
  135. .show_rport_supported_classes = 1,
  136. .show_host_fabric_name = 1,
  137. .show_starget_node_name = 1,
  138. .show_starget_port_name = 1,
  139. .show_starget_port_id = 1,
  140. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  141. .show_rport_dev_loss_tmo = 1,
  142. .get_fc_host_stats = fc_get_host_stats,
  143. .issue_fc_host_lip = fcoe_reset,
  144. .terminate_rport_io = fc_rport_terminate_io,
  145. .bsg_request = fc_lport_bsg_request,
  146. };
  147. static struct scsi_host_template fcoe_shost_template = {
  148. .module = THIS_MODULE,
  149. .name = "FCoE Driver",
  150. .proc_name = FCOE_NAME,
  151. .queuecommand = fc_queuecommand,
  152. .eh_abort_handler = fc_eh_abort,
  153. .eh_device_reset_handler = fc_eh_device_reset,
  154. .eh_host_reset_handler = fc_eh_host_reset,
  155. .slave_alloc = fc_slave_alloc,
  156. .change_queue_depth = fc_change_queue_depth,
  157. .change_queue_type = fc_change_queue_type,
  158. .this_id = -1,
  159. .cmd_per_lun = 3,
  160. .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
  161. .use_clustering = ENABLE_CLUSTERING,
  162. .sg_tablesize = SG_ALL,
  163. .max_sectors = 0xffff,
  164. };
  165. static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
  166. struct packet_type *ptype,
  167. struct net_device *orig_dev);
  168. /**
  169. * fcoe_interface_setup()
  170. * @fcoe: new fcoe_interface
  171. * @netdev : ptr to the associated netdevice struct
  172. *
  173. * Returns : 0 for success
  174. * Locking: must be called with the RTNL mutex held
  175. */
  176. static int fcoe_interface_setup(struct fcoe_interface *fcoe,
  177. struct net_device *netdev)
  178. {
  179. struct fcoe_ctlr *fip = &fcoe->ctlr;
  180. struct netdev_hw_addr *ha;
  181. u8 flogi_maddr[ETH_ALEN];
  182. const struct net_device_ops *ops;
  183. fcoe->netdev = netdev;
  184. /* Let LLD initialize for FCoE */
  185. ops = netdev->netdev_ops;
  186. if (ops->ndo_fcoe_enable) {
  187. if (ops->ndo_fcoe_enable(netdev))
  188. FCOE_NETDEV_DBG(netdev, "Failed to enable FCoE"
  189. " specific feature for LLD.\n");
  190. }
  191. /* Do not support for bonding device */
  192. if ((netdev->priv_flags & IFF_MASTER_ALB) ||
  193. (netdev->priv_flags & IFF_SLAVE_INACTIVE) ||
  194. (netdev->priv_flags & IFF_MASTER_8023AD)) {
  195. return -EOPNOTSUPP;
  196. }
  197. /* look for SAN MAC address, if multiple SAN MACs exist, only
  198. * use the first one for SPMA */
  199. rcu_read_lock();
  200. for_each_dev_addr(netdev, ha) {
  201. if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
  202. (is_valid_ether_addr(fip->ctl_src_addr))) {
  203. memcpy(fip->ctl_src_addr, ha->addr, ETH_ALEN);
  204. fip->spma = 1;
  205. break;
  206. }
  207. }
  208. rcu_read_unlock();
  209. /* setup Source Mac Address */
  210. if (!fip->spma)
  211. memcpy(fip->ctl_src_addr, netdev->dev_addr, netdev->addr_len);
  212. /*
  213. * Add FCoE MAC address as second unicast MAC address
  214. * or enter promiscuous mode if not capable of listening
  215. * for multiple unicast MACs.
  216. */
  217. memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
  218. dev_unicast_add(netdev, flogi_maddr);
  219. if (fip->spma)
  220. dev_unicast_add(netdev, fip->ctl_src_addr);
  221. dev_mc_add(netdev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
  222. /*
  223. * setup the receive function from ethernet driver
  224. * on the ethertype for the given device
  225. */
  226. fcoe->fcoe_packet_type.func = fcoe_rcv;
  227. fcoe->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
  228. fcoe->fcoe_packet_type.dev = netdev;
  229. dev_add_pack(&fcoe->fcoe_packet_type);
  230. fcoe->fip_packet_type.func = fcoe_fip_recv;
  231. fcoe->fip_packet_type.type = htons(ETH_P_FIP);
  232. fcoe->fip_packet_type.dev = netdev;
  233. dev_add_pack(&fcoe->fip_packet_type);
  234. return 0;
  235. }
  236. static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb);
  237. static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr);
  238. static u8 *fcoe_get_src_mac(struct fc_lport *lport);
  239. static void fcoe_destroy_work(struct work_struct *work);
  240. /**
  241. * fcoe_interface_create()
  242. * @netdev: network interface
  243. *
  244. * Returns: pointer to a struct fcoe_interface or NULL on error
  245. */
  246. static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev)
  247. {
  248. struct fcoe_interface *fcoe;
  249. fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL);
  250. if (!fcoe) {
  251. FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n");
  252. return NULL;
  253. }
  254. dev_hold(netdev);
  255. kref_init(&fcoe->kref);
  256. /*
  257. * Initialize FIP.
  258. */
  259. fcoe_ctlr_init(&fcoe->ctlr);
  260. fcoe->ctlr.send = fcoe_fip_send;
  261. fcoe->ctlr.update_mac = fcoe_update_src_mac;
  262. fcoe->ctlr.get_src_addr = fcoe_get_src_mac;
  263. fcoe_interface_setup(fcoe, netdev);
  264. return fcoe;
  265. }
  266. /**
  267. * fcoe_interface_cleanup() - clean up netdev configurations
  268. * @fcoe:
  269. *
  270. * Caller must be holding the RTNL mutex
  271. */
  272. void fcoe_interface_cleanup(struct fcoe_interface *fcoe)
  273. {
  274. struct net_device *netdev = fcoe->netdev;
  275. struct fcoe_ctlr *fip = &fcoe->ctlr;
  276. u8 flogi_maddr[ETH_ALEN];
  277. const struct net_device_ops *ops;
  278. /*
  279. * Don't listen for Ethernet packets anymore.
  280. * synchronize_net() ensures that the packet handlers are not running
  281. * on another CPU. dev_remove_pack() would do that, this calls the
  282. * unsyncronized version __dev_remove_pack() to avoid multiple delays.
  283. */
  284. __dev_remove_pack(&fcoe->fcoe_packet_type);
  285. __dev_remove_pack(&fcoe->fip_packet_type);
  286. synchronize_net();
  287. /* Delete secondary MAC addresses */
  288. memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
  289. dev_unicast_delete(netdev, flogi_maddr);
  290. if (fip->spma)
  291. dev_unicast_delete(netdev, fip->ctl_src_addr);
  292. dev_mc_delete(netdev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
  293. /* Tell the LLD we are done w/ FCoE */
  294. ops = netdev->netdev_ops;
  295. if (ops->ndo_fcoe_disable) {
  296. if (ops->ndo_fcoe_disable(netdev))
  297. FCOE_NETDEV_DBG(netdev, "Failed to disable FCoE"
  298. " specific feature for LLD.\n");
  299. }
  300. }
  301. /**
  302. * fcoe_interface_release() - fcoe_port kref release function
  303. * @kref: embedded reference count in an fcoe_interface struct
  304. */
  305. static void fcoe_interface_release(struct kref *kref)
  306. {
  307. struct fcoe_interface *fcoe;
  308. struct net_device *netdev;
  309. fcoe = container_of(kref, struct fcoe_interface, kref);
  310. netdev = fcoe->netdev;
  311. /* tear-down the FCoE controller */
  312. fcoe_ctlr_destroy(&fcoe->ctlr);
  313. kfree(fcoe);
  314. dev_put(netdev);
  315. }
  316. /**
  317. * fcoe_interface_get()
  318. * @fcoe:
  319. */
  320. static inline void fcoe_interface_get(struct fcoe_interface *fcoe)
  321. {
  322. kref_get(&fcoe->kref);
  323. }
  324. /**
  325. * fcoe_interface_put()
  326. * @fcoe:
  327. */
  328. static inline void fcoe_interface_put(struct fcoe_interface *fcoe)
  329. {
  330. kref_put(&fcoe->kref, fcoe_interface_release);
  331. }
  332. /**
  333. * fcoe_fip_recv - handle a received FIP frame.
  334. * @skb: the receive skb
  335. * @dev: associated &net_device
  336. * @ptype: the &packet_type structure which was used to register this handler.
  337. * @orig_dev: original receive &net_device, in case @dev is a bond.
  338. *
  339. * Returns: 0 for success
  340. */
  341. static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
  342. struct packet_type *ptype,
  343. struct net_device *orig_dev)
  344. {
  345. struct fcoe_interface *fcoe;
  346. fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type);
  347. fcoe_ctlr_recv(&fcoe->ctlr, skb);
  348. return 0;
  349. }
  350. /**
  351. * fcoe_fip_send() - send an Ethernet-encapsulated FIP frame.
  352. * @fip: FCoE controller.
  353. * @skb: FIP Packet.
  354. */
  355. static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
  356. {
  357. skb->dev = fcoe_from_ctlr(fip)->netdev;
  358. dev_queue_xmit(skb);
  359. }
  360. /**
  361. * fcoe_update_src_mac() - Update Ethernet MAC filters.
  362. * @lport: libfc lport
  363. * @addr: Unicast MAC address to add.
  364. *
  365. * Remove any previously-set unicast MAC filter.
  366. * Add secondary FCoE MAC address filter for our OUI.
  367. */
  368. static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr)
  369. {
  370. struct fcoe_port *port = lport_priv(lport);
  371. struct fcoe_interface *fcoe = port->fcoe;
  372. rtnl_lock();
  373. if (!is_zero_ether_addr(port->data_src_addr))
  374. dev_unicast_delete(fcoe->netdev, port->data_src_addr);
  375. if (!is_zero_ether_addr(addr))
  376. dev_unicast_add(fcoe->netdev, addr);
  377. memcpy(port->data_src_addr, addr, ETH_ALEN);
  378. rtnl_unlock();
  379. }
  380. /**
  381. * fcoe_get_src_mac() - return the Ethernet source address for an lport
  382. * @lport: libfc lport
  383. */
  384. static u8 *fcoe_get_src_mac(struct fc_lport *lport)
  385. {
  386. struct fcoe_port *port = lport_priv(lport);
  387. return port->data_src_addr;
  388. }
  389. /**
  390. * fcoe_lport_config() - sets up the fc_lport
  391. * @lp: ptr to the fc_lport
  392. *
  393. * Returns: 0 for success
  394. */
  395. static int fcoe_lport_config(struct fc_lport *lp)
  396. {
  397. lp->link_up = 0;
  398. lp->qfull = 0;
  399. lp->max_retry_count = 3;
  400. lp->max_rport_retry_count = 3;
  401. lp->e_d_tov = 2 * 1000; /* FC-FS default */
  402. lp->r_a_tov = 2 * 2 * 1000;
  403. lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
  404. FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
  405. lp->does_npiv = 1;
  406. fc_lport_init_stats(lp);
  407. /* lport fc_lport related configuration */
  408. fc_lport_config(lp);
  409. /* offload related configuration */
  410. lp->crc_offload = 0;
  411. lp->seq_offload = 0;
  412. lp->lro_enabled = 0;
  413. lp->lro_xid = 0;
  414. lp->lso_max = 0;
  415. return 0;
  416. }
  417. /**
  418. * fcoe_queue_timer() - fcoe queue timer
  419. * @lp: the fc_lport pointer
  420. *
  421. * Calls fcoe_check_wait_queue on timeout
  422. *
  423. */
  424. static void fcoe_queue_timer(ulong lp)
  425. {
  426. fcoe_check_wait_queue((struct fc_lport *)lp, NULL);
  427. }
  428. /**
  429. * fcoe_netdev_config() - Set up netdev for SW FCoE
  430. * @lp : ptr to the fc_lport
  431. * @netdev : ptr to the associated netdevice struct
  432. *
  433. * Must be called after fcoe_lport_config() as it will use lport mutex
  434. *
  435. * Returns : 0 for success
  436. */
  437. static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
  438. {
  439. u32 mfs;
  440. u64 wwnn, wwpn;
  441. struct fcoe_interface *fcoe;
  442. struct fcoe_port *port;
  443. /* Setup lport private data to point to fcoe softc */
  444. port = lport_priv(lp);
  445. fcoe = port->fcoe;
  446. /*
  447. * Determine max frame size based on underlying device and optional
  448. * user-configured limit. If the MFS is too low, fcoe_link_ok()
  449. * will return 0, so do this first.
  450. */
  451. mfs = netdev->mtu;
  452. if (netdev->features & NETIF_F_FCOE_MTU) {
  453. mfs = FCOE_MTU;
  454. FCOE_NETDEV_DBG(netdev, "Supports FCOE_MTU of %d bytes\n", mfs);
  455. }
  456. mfs -= (sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof));
  457. if (fc_set_mfs(lp, mfs))
  458. return -EINVAL;
  459. /* offload features support */
  460. if (netdev->features & NETIF_F_SG)
  461. lp->sg_supp = 1;
  462. if (netdev->features & NETIF_F_FCOE_CRC) {
  463. lp->crc_offload = 1;
  464. FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n");
  465. }
  466. if (netdev->features & NETIF_F_FSO) {
  467. lp->seq_offload = 1;
  468. lp->lso_max = netdev->gso_max_size;
  469. FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n",
  470. lp->lso_max);
  471. }
  472. if (netdev->fcoe_ddp_xid) {
  473. lp->lro_enabled = 1;
  474. lp->lro_xid = netdev->fcoe_ddp_xid;
  475. FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n",
  476. lp->lro_xid);
  477. }
  478. skb_queue_head_init(&port->fcoe_pending_queue);
  479. port->fcoe_pending_queue_active = 0;
  480. setup_timer(&port->timer, fcoe_queue_timer, (unsigned long)lp);
  481. if (!lp->vport) {
  482. wwnn = fcoe_wwn_from_mac(netdev->dev_addr, 1, 0);
  483. fc_set_wwnn(lp, wwnn);
  484. /* XXX - 3rd arg needs to be vlan id */
  485. wwpn = fcoe_wwn_from_mac(netdev->dev_addr, 2, 0);
  486. fc_set_wwpn(lp, wwpn);
  487. }
  488. return 0;
  489. }
  490. /**
  491. * fcoe_shost_config() - Sets up fc_lport->host
  492. * @lp : ptr to the fc_lport
  493. * @shost : ptr to the associated scsi host
  494. * @dev : device associated to scsi host
  495. *
  496. * Must be called after fcoe_lport_config() and fcoe_netdev_config()
  497. *
  498. * Returns : 0 for success
  499. */
  500. static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
  501. struct device *dev)
  502. {
  503. int rc = 0;
  504. /* lport scsi host config */
  505. lp->host->max_lun = FCOE_MAX_LUN;
  506. lp->host->max_id = FCOE_MAX_FCP_TARGET;
  507. lp->host->max_channel = 0;
  508. if (lp->vport)
  509. lp->host->transportt = fcoe_vport_transport_template;
  510. else
  511. lp->host->transportt = fcoe_transport_template;
  512. /* add the new host to the SCSI-ml */
  513. rc = scsi_add_host(lp->host, dev);
  514. if (rc) {
  515. FCOE_NETDEV_DBG(fcoe_netdev(lp), "fcoe_shost_config: "
  516. "error on scsi_add_host\n");
  517. return rc;
  518. }
  519. if (!lp->vport)
  520. fc_host_max_npiv_vports(lp->host) = USHORT_MAX;
  521. snprintf(fc_host_symbolic_name(lp->host), FC_SYMBOLIC_NAME_SIZE,
  522. "%s v%s over %s", FCOE_NAME, FCOE_VERSION,
  523. fcoe_netdev(lp)->name);
  524. return 0;
  525. }
  526. /*
  527. * fcoe_oem_match() - match for read types IO
  528. * @fp: the fc_frame for new IO.
  529. *
  530. * Returns : true for read types IO, otherwise returns false.
  531. */
  532. bool fcoe_oem_match(struct fc_frame *fp)
  533. {
  534. return fc_fcp_is_read(fr_fsp(fp)) &&
  535. (fr_fsp(fp)->data_len > fcoe_ddp_min);
  536. }
  537. /**
  538. * fcoe_em_config() - allocates em for this lport
  539. * @lp: the fcoe that em is to allocated for
  540. *
  541. * Returns : 0 on success
  542. */
  543. static inline int fcoe_em_config(struct fc_lport *lp)
  544. {
  545. struct fcoe_port *port = lport_priv(lp);
  546. struct fcoe_interface *fcoe = port->fcoe;
  547. struct fcoe_interface *oldfcoe = NULL;
  548. struct net_device *old_real_dev, *cur_real_dev;
  549. u16 min_xid = FCOE_MIN_XID;
  550. u16 max_xid = FCOE_MAX_XID;
  551. /*
  552. * Check if need to allocate an em instance for
  553. * offload exchange ids to be shared across all VN_PORTs/lport.
  554. */
  555. if (!lp->lro_enabled || !lp->lro_xid || (lp->lro_xid >= max_xid)) {
  556. lp->lro_xid = 0;
  557. goto skip_oem;
  558. }
  559. /*
  560. * Reuse existing offload em instance in case
  561. * it is already allocated on real eth device
  562. */
  563. if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
  564. cur_real_dev = vlan_dev_real_dev(fcoe->netdev);
  565. else
  566. cur_real_dev = fcoe->netdev;
  567. list_for_each_entry(oldfcoe, &fcoe_hostlist, list) {
  568. if (oldfcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
  569. old_real_dev = vlan_dev_real_dev(oldfcoe->netdev);
  570. else
  571. old_real_dev = oldfcoe->netdev;
  572. if (cur_real_dev == old_real_dev) {
  573. fcoe->oem = oldfcoe->oem;
  574. break;
  575. }
  576. }
  577. if (fcoe->oem) {
  578. if (!fc_exch_mgr_add(lp, fcoe->oem, fcoe_oem_match)) {
  579. printk(KERN_ERR "fcoe_em_config: failed to add "
  580. "offload em:%p on interface:%s\n",
  581. fcoe->oem, fcoe->netdev->name);
  582. return -ENOMEM;
  583. }
  584. } else {
  585. fcoe->oem = fc_exch_mgr_alloc(lp, FC_CLASS_3,
  586. FCOE_MIN_XID, lp->lro_xid,
  587. fcoe_oem_match);
  588. if (!fcoe->oem) {
  589. printk(KERN_ERR "fcoe_em_config: failed to allocate "
  590. "em for offload exches on interface:%s\n",
  591. fcoe->netdev->name);
  592. return -ENOMEM;
  593. }
  594. }
  595. /*
  596. * Exclude offload EM xid range from next EM xid range.
  597. */
  598. min_xid += lp->lro_xid + 1;
  599. skip_oem:
  600. if (!fc_exch_mgr_alloc(lp, FC_CLASS_3, min_xid, max_xid, NULL)) {
  601. printk(KERN_ERR "fcoe_em_config: failed to "
  602. "allocate em on interface %s\n", fcoe->netdev->name);
  603. return -ENOMEM;
  604. }
  605. return 0;
  606. }
  607. /**
  608. * fcoe_if_destroy() - FCoE software HBA tear-down function
  609. * @lport: fc_lport to destroy
  610. */
  611. static void fcoe_if_destroy(struct fc_lport *lport)
  612. {
  613. struct fcoe_port *port = lport_priv(lport);
  614. struct fcoe_interface *fcoe = port->fcoe;
  615. struct net_device *netdev = fcoe->netdev;
  616. FCOE_NETDEV_DBG(netdev, "Destroying interface\n");
  617. /* Logout of the fabric */
  618. fc_fabric_logoff(lport);
  619. /* Cleanup the fc_lport */
  620. fc_lport_destroy(lport);
  621. fc_fcp_destroy(lport);
  622. /* Stop the transmit retry timer */
  623. del_timer_sync(&port->timer);
  624. /* Free existing transmit skbs */
  625. fcoe_clean_pending_queue(lport);
  626. rtnl_lock();
  627. if (!is_zero_ether_addr(port->data_src_addr))
  628. dev_unicast_delete(netdev, port->data_src_addr);
  629. rtnl_unlock();
  630. /* receives may not be stopped until after this */
  631. fcoe_interface_put(fcoe);
  632. /* Free queued packets for the per-CPU receive threads */
  633. fcoe_percpu_clean(lport);
  634. /* Detach from the scsi-ml */
  635. fc_remove_host(lport->host);
  636. scsi_remove_host(lport->host);
  637. /* There are no more rports or I/O, free the EM */
  638. fc_exch_mgr_free(lport);
  639. /* Free memory used by statistical counters */
  640. fc_lport_free_stats(lport);
  641. /* Release the Scsi_Host */
  642. scsi_host_put(lport->host);
  643. }
  644. /*
  645. * fcoe_ddp_setup - calls LLD's ddp_setup through net_device
  646. * @lp: the corresponding fc_lport
  647. * @xid: the exchange id for this ddp transfer
  648. * @sgl: the scatterlist describing this transfer
  649. * @sgc: number of sg items
  650. *
  651. * Returns : 0 no ddp
  652. */
  653. static int fcoe_ddp_setup(struct fc_lport *lp, u16 xid,
  654. struct scatterlist *sgl, unsigned int sgc)
  655. {
  656. struct net_device *n = fcoe_netdev(lp);
  657. if (n->netdev_ops->ndo_fcoe_ddp_setup)
  658. return n->netdev_ops->ndo_fcoe_ddp_setup(n, xid, sgl, sgc);
  659. return 0;
  660. }
  661. /*
  662. * fcoe_ddp_done - calls LLD's ddp_done through net_device
  663. * @lp: the corresponding fc_lport
  664. * @xid: the exchange id for this ddp transfer
  665. *
  666. * Returns : the length of data that have been completed by ddp
  667. */
  668. static int fcoe_ddp_done(struct fc_lport *lp, u16 xid)
  669. {
  670. struct net_device *n = fcoe_netdev(lp);
  671. if (n->netdev_ops->ndo_fcoe_ddp_done)
  672. return n->netdev_ops->ndo_fcoe_ddp_done(n, xid);
  673. return 0;
  674. }
  675. static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport,
  676. u32 did, struct fc_frame *fp, unsigned int op,
  677. void (*resp)(struct fc_seq *, struct fc_frame *, void *),
  678. void *arg, u32 timeout);
  679. static struct libfc_function_template fcoe_libfc_fcn_templ = {
  680. .frame_send = fcoe_xmit,
  681. .ddp_setup = fcoe_ddp_setup,
  682. .ddp_done = fcoe_ddp_done,
  683. .elsct_send = fcoe_elsct_send,
  684. };
  685. /**
  686. * fcoe_if_create() - this function creates the fcoe port
  687. * @fcoe: fcoe_interface structure to create an fc_lport instance on
  688. * @parent: device pointer to be the parent in sysfs for the SCSI host
  689. * @npiv: is this a vport?
  690. *
  691. * Creates fc_lport struct and scsi_host for lport, configures lport.
  692. *
  693. * Returns : The allocated fc_lport or an error pointer
  694. */
  695. static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
  696. struct device *parent, int npiv)
  697. {
  698. int rc;
  699. struct fc_lport *lport = NULL;
  700. struct fcoe_port *port;
  701. struct Scsi_Host *shost;
  702. struct net_device *netdev = fcoe->netdev;
  703. /*
  704. * parent is only a vport if npiv is 1,
  705. * but we'll only use vport in that case so go ahead and set it
  706. */
  707. struct fc_vport *vport = dev_to_vport(parent);
  708. FCOE_NETDEV_DBG(netdev, "Create Interface\n");
  709. if (!npiv) {
  710. lport = libfc_host_alloc(&fcoe_shost_template,
  711. sizeof(struct fcoe_port));
  712. } else {
  713. lport = libfc_vport_create(vport,
  714. sizeof(struct fcoe_port));
  715. }
  716. if (!lport) {
  717. FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n");
  718. rc = -ENOMEM;
  719. goto out;
  720. }
  721. shost = lport->host;
  722. port = lport_priv(lport);
  723. port->lport = lport;
  724. port->fcoe = fcoe;
  725. INIT_WORK(&port->destroy_work, fcoe_destroy_work);
  726. /* configure fc_lport, e.g., em */
  727. rc = fcoe_lport_config(lport);
  728. if (rc) {
  729. FCOE_NETDEV_DBG(netdev, "Could not configure lport for the "
  730. "interface\n");
  731. goto out_host_put;
  732. }
  733. if (npiv) {
  734. FCOE_NETDEV_DBG(netdev, "Setting vport names, 0x%llX 0x%llX\n",
  735. vport->node_name, vport->port_name);
  736. fc_set_wwnn(lport, vport->node_name);
  737. fc_set_wwpn(lport, vport->port_name);
  738. }
  739. /* configure lport network properties */
  740. rc = fcoe_netdev_config(lport, netdev);
  741. if (rc) {
  742. FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the "
  743. "interface\n");
  744. goto out_lp_destroy;
  745. }
  746. /* configure lport scsi host properties */
  747. rc = fcoe_shost_config(lport, shost, parent);
  748. if (rc) {
  749. FCOE_NETDEV_DBG(netdev, "Could not configure shost for the "
  750. "interface\n");
  751. goto out_lp_destroy;
  752. }
  753. /* Initialize the library */
  754. rc = fcoe_libfc_config(lport, &fcoe_libfc_fcn_templ);
  755. if (rc) {
  756. FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the "
  757. "interface\n");
  758. goto out_lp_destroy;
  759. }
  760. if (!npiv) {
  761. /*
  762. * fcoe_em_alloc() and fcoe_hostlist_add() both
  763. * need to be atomic with respect to other changes to the
  764. * hostlist since fcoe_em_alloc() looks for an existing EM
  765. * instance on host list updated by fcoe_hostlist_add().
  766. *
  767. * This is currently handled through the fcoe_config_mutex
  768. * begin held.
  769. */
  770. /* lport exch manager allocation */
  771. rc = fcoe_em_config(lport);
  772. if (rc) {
  773. FCOE_NETDEV_DBG(netdev, "Could not configure the EM "
  774. "for the interface\n");
  775. goto out_lp_destroy;
  776. }
  777. }
  778. fcoe_interface_get(fcoe);
  779. return lport;
  780. out_lp_destroy:
  781. fc_exch_mgr_free(lport);
  782. out_host_put:
  783. scsi_host_put(lport->host);
  784. out:
  785. return ERR_PTR(rc);
  786. }
  787. /**
  788. * fcoe_if_init() - attach to scsi transport
  789. *
  790. * Returns : 0 on success
  791. */
  792. static int __init fcoe_if_init(void)
  793. {
  794. /* attach to scsi transport */
  795. fcoe_transport_template = fc_attach_transport(&fcoe_transport_function);
  796. fcoe_vport_transport_template =
  797. fc_attach_transport(&fcoe_vport_transport_function);
  798. if (!fcoe_transport_template) {
  799. printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
  800. return -ENODEV;
  801. }
  802. return 0;
  803. }
  804. /**
  805. * fcoe_if_exit() - detach from scsi transport
  806. *
  807. * Returns : 0 on success
  808. */
  809. int __exit fcoe_if_exit(void)
  810. {
  811. fc_release_transport(fcoe_transport_template);
  812. fc_release_transport(fcoe_vport_transport_template);
  813. fcoe_transport_template = NULL;
  814. fcoe_vport_transport_template = NULL;
  815. return 0;
  816. }
  817. /**
  818. * fcoe_percpu_thread_create() - Create a receive thread for an online cpu
  819. * @cpu: cpu index for the online cpu
  820. */
  821. static void fcoe_percpu_thread_create(unsigned int cpu)
  822. {
  823. struct fcoe_percpu_s *p;
  824. struct task_struct *thread;
  825. p = &per_cpu(fcoe_percpu, cpu);
  826. thread = kthread_create(fcoe_percpu_receive_thread,
  827. (void *)p, "fcoethread/%d", cpu);
  828. if (likely(!IS_ERR(thread))) {
  829. kthread_bind(thread, cpu);
  830. wake_up_process(thread);
  831. spin_lock_bh(&p->fcoe_rx_list.lock);
  832. p->thread = thread;
  833. spin_unlock_bh(&p->fcoe_rx_list.lock);
  834. }
  835. }
  836. /**
  837. * fcoe_percpu_thread_destroy() - removes the rx thread for the given cpu
  838. * @cpu: cpu index the rx thread is to be removed
  839. *
  840. * Destroys a per-CPU Rx thread. Any pending skbs are moved to the
  841. * current CPU's Rx thread. If the thread being destroyed is bound to
  842. * the CPU processing this context the skbs will be freed.
  843. */
  844. static void fcoe_percpu_thread_destroy(unsigned int cpu)
  845. {
  846. struct fcoe_percpu_s *p;
  847. struct task_struct *thread;
  848. struct page *crc_eof;
  849. struct sk_buff *skb;
  850. #ifdef CONFIG_SMP
  851. struct fcoe_percpu_s *p0;
  852. unsigned targ_cpu = smp_processor_id();
  853. #endif /* CONFIG_SMP */
  854. FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
  855. /* Prevent any new skbs from being queued for this CPU. */
  856. p = &per_cpu(fcoe_percpu, cpu);
  857. spin_lock_bh(&p->fcoe_rx_list.lock);
  858. thread = p->thread;
  859. p->thread = NULL;
  860. crc_eof = p->crc_eof_page;
  861. p->crc_eof_page = NULL;
  862. p->crc_eof_offset = 0;
  863. spin_unlock_bh(&p->fcoe_rx_list.lock);
  864. #ifdef CONFIG_SMP
  865. /*
  866. * Don't bother moving the skb's if this context is running
  867. * on the same CPU that is having its thread destroyed. This
  868. * can easily happen when the module is removed.
  869. */
  870. if (cpu != targ_cpu) {
  871. p0 = &per_cpu(fcoe_percpu, targ_cpu);
  872. spin_lock_bh(&p0->fcoe_rx_list.lock);
  873. if (p0->thread) {
  874. FCOE_DBG("Moving frames from CPU %d to CPU %d\n",
  875. cpu, targ_cpu);
  876. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  877. __skb_queue_tail(&p0->fcoe_rx_list, skb);
  878. spin_unlock_bh(&p0->fcoe_rx_list.lock);
  879. } else {
  880. /*
  881. * The targeted CPU is not initialized and cannot accept
  882. * new skbs. Unlock the targeted CPU and drop the skbs
  883. * on the CPU that is going offline.
  884. */
  885. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  886. kfree_skb(skb);
  887. spin_unlock_bh(&p0->fcoe_rx_list.lock);
  888. }
  889. } else {
  890. /*
  891. * This scenario occurs when the module is being removed
  892. * and all threads are being destroyed. skbs will continue
  893. * to be shifted from the CPU thread that is being removed
  894. * to the CPU thread associated with the CPU that is processing
  895. * the module removal. Once there is only one CPU Rx thread it
  896. * will reach this case and we will drop all skbs and later
  897. * stop the thread.
  898. */
  899. spin_lock_bh(&p->fcoe_rx_list.lock);
  900. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  901. kfree_skb(skb);
  902. spin_unlock_bh(&p->fcoe_rx_list.lock);
  903. }
  904. #else
  905. /*
  906. * This a non-SMP scenario where the singular Rx thread is
  907. * being removed. Free all skbs and stop the thread.
  908. */
  909. spin_lock_bh(&p->fcoe_rx_list.lock);
  910. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  911. kfree_skb(skb);
  912. spin_unlock_bh(&p->fcoe_rx_list.lock);
  913. #endif
  914. if (thread)
  915. kthread_stop(thread);
  916. if (crc_eof)
  917. put_page(crc_eof);
  918. }
  919. /**
  920. * fcoe_cpu_callback() - fcoe cpu hotplug event callback
  921. * @nfb: callback data block
  922. * @action: event triggering the callback
  923. * @hcpu: index for the cpu of this event
  924. *
  925. * This creates or destroys per cpu data for fcoe
  926. *
  927. * Returns NOTIFY_OK always.
  928. */
  929. static int fcoe_cpu_callback(struct notifier_block *nfb,
  930. unsigned long action, void *hcpu)
  931. {
  932. unsigned cpu = (unsigned long)hcpu;
  933. switch (action) {
  934. case CPU_ONLINE:
  935. case CPU_ONLINE_FROZEN:
  936. FCOE_DBG("CPU %x online: Create Rx thread\n", cpu);
  937. fcoe_percpu_thread_create(cpu);
  938. break;
  939. case CPU_DEAD:
  940. case CPU_DEAD_FROZEN:
  941. FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu);
  942. fcoe_percpu_thread_destroy(cpu);
  943. break;
  944. default:
  945. break;
  946. }
  947. return NOTIFY_OK;
  948. }
  949. static struct notifier_block fcoe_cpu_notifier = {
  950. .notifier_call = fcoe_cpu_callback,
  951. };
  952. /**
  953. * fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ
  954. * @skb: the receive skb
  955. * @dev: associated net device
  956. * @ptype: context
  957. * @olddev: last device
  958. *
  959. * this function will receive the packet and build fc frame and pass it up
  960. *
  961. * Returns: 0 for success
  962. */
  963. int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
  964. struct packet_type *ptype, struct net_device *olddev)
  965. {
  966. struct fc_lport *lp;
  967. struct fcoe_rcv_info *fr;
  968. struct fcoe_interface *fcoe;
  969. struct fc_frame_header *fh;
  970. struct fcoe_percpu_s *fps;
  971. unsigned int cpu;
  972. fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type);
  973. lp = fcoe->ctlr.lp;
  974. if (unlikely(lp == NULL)) {
  975. FCOE_NETDEV_DBG(dev, "Cannot find hba structure");
  976. goto err2;
  977. }
  978. if (!lp->link_up)
  979. goto err2;
  980. FCOE_NETDEV_DBG(dev, "skb_info: len:%d data_len:%d head:%p "
  981. "data:%p tail:%p end:%p sum:%d dev:%s",
  982. skb->len, skb->data_len, skb->head, skb->data,
  983. skb_tail_pointer(skb), skb_end_pointer(skb),
  984. skb->csum, skb->dev ? skb->dev->name : "<NULL>");
  985. /* check for FCOE packet type */
  986. if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
  987. FCOE_NETDEV_DBG(dev, "Wrong FC type frame");
  988. goto err;
  989. }
  990. /*
  991. * Check for minimum frame length, and make sure required FCoE
  992. * and FC headers are pulled into the linear data area.
  993. */
  994. if (unlikely((skb->len < FCOE_MIN_FRAME) ||
  995. !pskb_may_pull(skb, FCOE_HEADER_LEN)))
  996. goto err;
  997. skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
  998. fh = (struct fc_frame_header *) skb_transport_header(skb);
  999. fr = fcoe_dev_from_skb(skb);
  1000. fr->fr_dev = lp;
  1001. fr->ptype = ptype;
  1002. /*
  1003. * In case the incoming frame's exchange is originated from
  1004. * the initiator, then received frame's exchange id is ANDed
  1005. * with fc_cpu_mask bits to get the same cpu on which exchange
  1006. * was originated, otherwise just use the current cpu.
  1007. */
  1008. if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX)
  1009. cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask;
  1010. else
  1011. cpu = smp_processor_id();
  1012. fps = &per_cpu(fcoe_percpu, cpu);
  1013. spin_lock_bh(&fps->fcoe_rx_list.lock);
  1014. if (unlikely(!fps->thread)) {
  1015. /*
  1016. * The targeted CPU is not ready, let's target
  1017. * the first CPU now. For non-SMP systems this
  1018. * will check the same CPU twice.
  1019. */
  1020. FCOE_NETDEV_DBG(dev, "CPU is online, but no receive thread "
  1021. "ready for incoming skb- using first online "
  1022. "CPU.\n");
  1023. spin_unlock_bh(&fps->fcoe_rx_list.lock);
  1024. cpu = first_cpu(cpu_online_map);
  1025. fps = &per_cpu(fcoe_percpu, cpu);
  1026. spin_lock_bh(&fps->fcoe_rx_list.lock);
  1027. if (!fps->thread) {
  1028. spin_unlock_bh(&fps->fcoe_rx_list.lock);
  1029. goto err;
  1030. }
  1031. }
  1032. /*
  1033. * We now have a valid CPU that we're targeting for
  1034. * this skb. We also have this receive thread locked,
  1035. * so we're free to queue skbs into it's queue.
  1036. */
  1037. __skb_queue_tail(&fps->fcoe_rx_list, skb);
  1038. if (fps->fcoe_rx_list.qlen == 1)
  1039. wake_up_process(fps->thread);
  1040. spin_unlock_bh(&fps->fcoe_rx_list.lock);
  1041. return 0;
  1042. err:
  1043. fc_lport_get_stats(lp)->ErrorFrames++;
  1044. err2:
  1045. kfree_skb(skb);
  1046. return -1;
  1047. }
  1048. /**
  1049. * fcoe_start_io() - pass to netdev to start xmit for fcoe
  1050. * @skb: the skb to be xmitted
  1051. *
  1052. * Returns: 0 for success
  1053. */
  1054. static inline int fcoe_start_io(struct sk_buff *skb)
  1055. {
  1056. int rc;
  1057. skb_get(skb);
  1058. rc = dev_queue_xmit(skb);
  1059. if (rc != 0)
  1060. return rc;
  1061. kfree_skb(skb);
  1062. return 0;
  1063. }
  1064. /**
  1065. * fcoe_get_paged_crc_eof() - in case we need to alloc a page for crc_eof
  1066. * @skb: the skb to be xmitted
  1067. * @tlen: total len
  1068. *
  1069. * Returns: 0 for success
  1070. */
  1071. static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
  1072. {
  1073. struct fcoe_percpu_s *fps;
  1074. struct page *page;
  1075. fps = &get_cpu_var(fcoe_percpu);
  1076. page = fps->crc_eof_page;
  1077. if (!page) {
  1078. page = alloc_page(GFP_ATOMIC);
  1079. if (!page) {
  1080. put_cpu_var(fcoe_percpu);
  1081. return -ENOMEM;
  1082. }
  1083. fps->crc_eof_page = page;
  1084. fps->crc_eof_offset = 0;
  1085. }
  1086. get_page(page);
  1087. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
  1088. fps->crc_eof_offset, tlen);
  1089. skb->len += tlen;
  1090. skb->data_len += tlen;
  1091. skb->truesize += tlen;
  1092. fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
  1093. if (fps->crc_eof_offset >= PAGE_SIZE) {
  1094. fps->crc_eof_page = NULL;
  1095. fps->crc_eof_offset = 0;
  1096. put_page(page);
  1097. }
  1098. put_cpu_var(fcoe_percpu);
  1099. return 0;
  1100. }
  1101. /**
  1102. * fcoe_fc_crc() - calculates FC CRC in this fcoe skb
  1103. * @fp: the fc_frame containing data to be checksummed
  1104. *
  1105. * This uses crc32() to calculate the crc for port frame
  1106. * Return : 32 bit crc
  1107. */
  1108. u32 fcoe_fc_crc(struct fc_frame *fp)
  1109. {
  1110. struct sk_buff *skb = fp_skb(fp);
  1111. struct skb_frag_struct *frag;
  1112. unsigned char *data;
  1113. unsigned long off, len, clen;
  1114. u32 crc;
  1115. unsigned i;
  1116. crc = crc32(~0, skb->data, skb_headlen(skb));
  1117. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1118. frag = &skb_shinfo(skb)->frags[i];
  1119. off = frag->page_offset;
  1120. len = frag->size;
  1121. while (len > 0) {
  1122. clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
  1123. data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
  1124. KM_SKB_DATA_SOFTIRQ);
  1125. crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
  1126. kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
  1127. off += clen;
  1128. len -= clen;
  1129. }
  1130. }
  1131. return crc;
  1132. }
  1133. /**
  1134. * fcoe_xmit() - FCoE frame transmit function
  1135. * @lp: the associated local fcoe
  1136. * @fp: the fc_frame to be transmitted
  1137. *
  1138. * Return : 0 for success
  1139. */
  1140. int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
  1141. {
  1142. int wlen;
  1143. u32 crc;
  1144. struct ethhdr *eh;
  1145. struct fcoe_crc_eof *cp;
  1146. struct sk_buff *skb;
  1147. struct fcoe_dev_stats *stats;
  1148. struct fc_frame_header *fh;
  1149. unsigned int hlen; /* header length implies the version */
  1150. unsigned int tlen; /* trailer length */
  1151. unsigned int elen; /* eth header, may include vlan */
  1152. struct fcoe_port *port = lport_priv(lp);
  1153. struct fcoe_interface *fcoe = port->fcoe;
  1154. u8 sof, eof;
  1155. struct fcoe_hdr *hp;
  1156. WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
  1157. fh = fc_frame_header_get(fp);
  1158. skb = fp_skb(fp);
  1159. wlen = skb->len / FCOE_WORD_TO_BYTE;
  1160. if (!lp->link_up) {
  1161. kfree_skb(skb);
  1162. return 0;
  1163. }
  1164. if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
  1165. fcoe_ctlr_els_send(&fcoe->ctlr, lp, skb))
  1166. return 0;
  1167. sof = fr_sof(fp);
  1168. eof = fr_eof(fp);
  1169. elen = sizeof(struct ethhdr);
  1170. hlen = sizeof(struct fcoe_hdr);
  1171. tlen = sizeof(struct fcoe_crc_eof);
  1172. wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
  1173. /* crc offload */
  1174. if (likely(lp->crc_offload)) {
  1175. skb->ip_summed = CHECKSUM_PARTIAL;
  1176. skb->csum_start = skb_headroom(skb);
  1177. skb->csum_offset = skb->len;
  1178. crc = 0;
  1179. } else {
  1180. skb->ip_summed = CHECKSUM_NONE;
  1181. crc = fcoe_fc_crc(fp);
  1182. }
  1183. /* copy port crc and eof to the skb buff */
  1184. if (skb_is_nonlinear(skb)) {
  1185. skb_frag_t *frag;
  1186. if (fcoe_get_paged_crc_eof(skb, tlen)) {
  1187. kfree_skb(skb);
  1188. return -ENOMEM;
  1189. }
  1190. frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
  1191. cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
  1192. + frag->page_offset;
  1193. } else {
  1194. cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
  1195. }
  1196. memset(cp, 0, sizeof(*cp));
  1197. cp->fcoe_eof = eof;
  1198. cp->fcoe_crc32 = cpu_to_le32(~crc);
  1199. if (skb_is_nonlinear(skb)) {
  1200. kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
  1201. cp = NULL;
  1202. }
  1203. /* adjust skb network/transport offsets to match mac/fcoe/port */
  1204. skb_push(skb, elen + hlen);
  1205. skb_reset_mac_header(skb);
  1206. skb_reset_network_header(skb);
  1207. skb->mac_len = elen;
  1208. skb->protocol = htons(ETH_P_FCOE);
  1209. skb->dev = fcoe->netdev;
  1210. /* fill up mac and fcoe headers */
  1211. eh = eth_hdr(skb);
  1212. eh->h_proto = htons(ETH_P_FCOE);
  1213. if (fcoe->ctlr.map_dest)
  1214. fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
  1215. else
  1216. /* insert GW address */
  1217. memcpy(eh->h_dest, fcoe->ctlr.dest_addr, ETH_ALEN);
  1218. if (unlikely(fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN))
  1219. memcpy(eh->h_source, fcoe->ctlr.ctl_src_addr, ETH_ALEN);
  1220. else
  1221. memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
  1222. hp = (struct fcoe_hdr *)(eh + 1);
  1223. memset(hp, 0, sizeof(*hp));
  1224. if (FC_FCOE_VER)
  1225. FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
  1226. hp->fcoe_sof = sof;
  1227. /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
  1228. if (lp->seq_offload && fr_max_payload(fp)) {
  1229. skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
  1230. skb_shinfo(skb)->gso_size = fr_max_payload(fp);
  1231. } else {
  1232. skb_shinfo(skb)->gso_type = 0;
  1233. skb_shinfo(skb)->gso_size = 0;
  1234. }
  1235. /* update tx stats: regardless if LLD fails */
  1236. stats = fc_lport_get_stats(lp);
  1237. stats->TxFrames++;
  1238. stats->TxWords += wlen;
  1239. /* send down to lld */
  1240. fr_dev(fp) = lp;
  1241. if (port->fcoe_pending_queue.qlen)
  1242. fcoe_check_wait_queue(lp, skb);
  1243. else if (fcoe_start_io(skb))
  1244. fcoe_check_wait_queue(lp, skb);
  1245. return 0;
  1246. }
  1247. /**
  1248. * fcoe_percpu_flush_done() - Indicate percpu queue flush completion.
  1249. * @skb: the skb being completed.
  1250. */
  1251. static void fcoe_percpu_flush_done(struct sk_buff *skb)
  1252. {
  1253. complete(&fcoe_flush_completion);
  1254. }
  1255. /**
  1256. * fcoe_percpu_receive_thread() - recv thread per cpu
  1257. * @arg: ptr to the fcoe per cpu struct
  1258. *
  1259. * Return: 0 for success
  1260. */
  1261. int fcoe_percpu_receive_thread(void *arg)
  1262. {
  1263. struct fcoe_percpu_s *p = arg;
  1264. u32 fr_len;
  1265. struct fc_lport *lp;
  1266. struct fcoe_rcv_info *fr;
  1267. struct fcoe_dev_stats *stats;
  1268. struct fc_frame_header *fh;
  1269. struct sk_buff *skb;
  1270. struct fcoe_crc_eof crc_eof;
  1271. struct fc_frame *fp;
  1272. u8 *mac = NULL;
  1273. struct fcoe_port *port;
  1274. struct fcoe_hdr *hp;
  1275. set_user_nice(current, -20);
  1276. while (!kthread_should_stop()) {
  1277. spin_lock_bh(&p->fcoe_rx_list.lock);
  1278. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) {
  1279. set_current_state(TASK_INTERRUPTIBLE);
  1280. spin_unlock_bh(&p->fcoe_rx_list.lock);
  1281. schedule();
  1282. set_current_state(TASK_RUNNING);
  1283. if (kthread_should_stop())
  1284. return 0;
  1285. spin_lock_bh(&p->fcoe_rx_list.lock);
  1286. }
  1287. spin_unlock_bh(&p->fcoe_rx_list.lock);
  1288. fr = fcoe_dev_from_skb(skb);
  1289. lp = fr->fr_dev;
  1290. if (unlikely(lp == NULL)) {
  1291. if (skb->destructor != fcoe_percpu_flush_done)
  1292. FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb");
  1293. kfree_skb(skb);
  1294. continue;
  1295. }
  1296. FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d "
  1297. "head:%p data:%p tail:%p end:%p sum:%d dev:%s",
  1298. skb->len, skb->data_len,
  1299. skb->head, skb->data, skb_tail_pointer(skb),
  1300. skb_end_pointer(skb), skb->csum,
  1301. skb->dev ? skb->dev->name : "<NULL>");
  1302. /*
  1303. * Save source MAC address before discarding header.
  1304. */
  1305. port = lport_priv(lp);
  1306. if (skb_is_nonlinear(skb))
  1307. skb_linearize(skb); /* not ideal */
  1308. mac = eth_hdr(skb)->h_source;
  1309. /*
  1310. * Frame length checks and setting up the header pointers
  1311. * was done in fcoe_rcv already.
  1312. */
  1313. hp = (struct fcoe_hdr *) skb_network_header(skb);
  1314. fh = (struct fc_frame_header *) skb_transport_header(skb);
  1315. stats = fc_lport_get_stats(lp);
  1316. if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
  1317. if (stats->ErrorFrames < 5)
  1318. printk(KERN_WARNING "fcoe: FCoE version "
  1319. "mismatch: The frame has "
  1320. "version %x, but the "
  1321. "initiator supports version "
  1322. "%x\n", FC_FCOE_DECAPS_VER(hp),
  1323. FC_FCOE_VER);
  1324. stats->ErrorFrames++;
  1325. kfree_skb(skb);
  1326. continue;
  1327. }
  1328. skb_pull(skb, sizeof(struct fcoe_hdr));
  1329. fr_len = skb->len - sizeof(struct fcoe_crc_eof);
  1330. stats->RxFrames++;
  1331. stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
  1332. fp = (struct fc_frame *)skb;
  1333. fc_frame_init(fp);
  1334. fr_dev(fp) = lp;
  1335. fr_sof(fp) = hp->fcoe_sof;
  1336. /* Copy out the CRC and EOF trailer for access */
  1337. if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
  1338. kfree_skb(skb);
  1339. continue;
  1340. }
  1341. fr_eof(fp) = crc_eof.fcoe_eof;
  1342. fr_crc(fp) = crc_eof.fcoe_crc32;
  1343. if (pskb_trim(skb, fr_len)) {
  1344. kfree_skb(skb);
  1345. continue;
  1346. }
  1347. /*
  1348. * We only check CRC if no offload is available and if it is
  1349. * it's solicited data, in which case, the FCP layer would
  1350. * check it during the copy.
  1351. */
  1352. if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
  1353. fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
  1354. else
  1355. fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
  1356. fh = fc_frame_header_get(fp);
  1357. if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
  1358. fh->fh_type == FC_TYPE_FCP) {
  1359. fc_exch_recv(lp, fp);
  1360. continue;
  1361. }
  1362. if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
  1363. if (le32_to_cpu(fr_crc(fp)) !=
  1364. ~crc32(~0, skb->data, fr_len)) {
  1365. if (stats->InvalidCRCCount < 5)
  1366. printk(KERN_WARNING "fcoe: dropping "
  1367. "frame with CRC error\n");
  1368. stats->InvalidCRCCount++;
  1369. stats->ErrorFrames++;
  1370. fc_frame_free(fp);
  1371. continue;
  1372. }
  1373. fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
  1374. }
  1375. fc_exch_recv(lp, fp);
  1376. }
  1377. return 0;
  1378. }
  1379. /**
  1380. * fcoe_check_wait_queue() - attempt to clear the transmit backlog
  1381. * @lp: the fc_lport
  1382. *
  1383. * This empties the wait_queue, dequeue the head of the wait_queue queue
  1384. * and calls fcoe_start_io() for each packet, if all skb have been
  1385. * transmitted, return qlen or -1 if a error occurs, then restore
  1386. * wait_queue and try again later.
  1387. *
  1388. * The wait_queue is used when the skb transmit fails. skb will go
  1389. * in the wait_queue which will be emptied by the timer function or
  1390. * by the next skb transmit.
  1391. */
  1392. static void fcoe_check_wait_queue(struct fc_lport *lp, struct sk_buff *skb)
  1393. {
  1394. struct fcoe_port *port = lport_priv(lp);
  1395. int rc;
  1396. spin_lock_bh(&port->fcoe_pending_queue.lock);
  1397. if (skb)
  1398. __skb_queue_tail(&port->fcoe_pending_queue, skb);
  1399. if (port->fcoe_pending_queue_active)
  1400. goto out;
  1401. port->fcoe_pending_queue_active = 1;
  1402. while (port->fcoe_pending_queue.qlen) {
  1403. /* keep qlen > 0 until fcoe_start_io succeeds */
  1404. port->fcoe_pending_queue.qlen++;
  1405. skb = __skb_dequeue(&port->fcoe_pending_queue);
  1406. spin_unlock_bh(&port->fcoe_pending_queue.lock);
  1407. rc = fcoe_start_io(skb);
  1408. spin_lock_bh(&port->fcoe_pending_queue.lock);
  1409. if (rc) {
  1410. __skb_queue_head(&port->fcoe_pending_queue, skb);
  1411. /* undo temporary increment above */
  1412. port->fcoe_pending_queue.qlen--;
  1413. break;
  1414. }
  1415. /* undo temporary increment above */
  1416. port->fcoe_pending_queue.qlen--;
  1417. }
  1418. if (port->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
  1419. lp->qfull = 0;
  1420. if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer))
  1421. mod_timer(&port->timer, jiffies + 2);
  1422. port->fcoe_pending_queue_active = 0;
  1423. out:
  1424. if (port->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
  1425. lp->qfull = 1;
  1426. spin_unlock_bh(&port->fcoe_pending_queue.lock);
  1427. return;
  1428. }
  1429. /**
  1430. * fcoe_dev_setup() - setup link change notification interface
  1431. */
  1432. static void fcoe_dev_setup(void)
  1433. {
  1434. register_netdevice_notifier(&fcoe_notifier);
  1435. }
  1436. /**
  1437. * fcoe_dev_cleanup() - cleanup link change notification interface
  1438. */
  1439. static void fcoe_dev_cleanup(void)
  1440. {
  1441. unregister_netdevice_notifier(&fcoe_notifier);
  1442. }
  1443. /**
  1444. * fcoe_device_notification() - netdev event notification callback
  1445. * @notifier: context of the notification
  1446. * @event: type of event
  1447. * @ptr: fixed array for output parsed ifname
  1448. *
  1449. * This function is called by the ethernet driver in case of link change event
  1450. *
  1451. * Returns: 0 for success
  1452. */
  1453. static int fcoe_device_notification(struct notifier_block *notifier,
  1454. ulong event, void *ptr)
  1455. {
  1456. struct fc_lport *lp = NULL;
  1457. struct net_device *netdev = ptr;
  1458. struct fcoe_interface *fcoe;
  1459. struct fcoe_port *port;
  1460. struct fcoe_dev_stats *stats;
  1461. u32 link_possible = 1;
  1462. u32 mfs;
  1463. int rc = NOTIFY_OK;
  1464. list_for_each_entry(fcoe, &fcoe_hostlist, list) {
  1465. if (fcoe->netdev == netdev) {
  1466. lp = fcoe->ctlr.lp;
  1467. break;
  1468. }
  1469. }
  1470. if (lp == NULL) {
  1471. rc = NOTIFY_DONE;
  1472. goto out;
  1473. }
  1474. switch (event) {
  1475. case NETDEV_DOWN:
  1476. case NETDEV_GOING_DOWN:
  1477. link_possible = 0;
  1478. break;
  1479. case NETDEV_UP:
  1480. case NETDEV_CHANGE:
  1481. break;
  1482. case NETDEV_CHANGEMTU:
  1483. if (netdev->features & NETIF_F_FCOE_MTU)
  1484. break;
  1485. mfs = netdev->mtu - (sizeof(struct fcoe_hdr) +
  1486. sizeof(struct fcoe_crc_eof));
  1487. if (mfs >= FC_MIN_MAX_FRAME)
  1488. fc_set_mfs(lp, mfs);
  1489. break;
  1490. case NETDEV_REGISTER:
  1491. break;
  1492. case NETDEV_UNREGISTER:
  1493. list_del(&fcoe->list);
  1494. port = lport_priv(fcoe->ctlr.lp);
  1495. fcoe_interface_cleanup(fcoe);
  1496. schedule_work(&port->destroy_work);
  1497. goto out;
  1498. break;
  1499. default:
  1500. FCOE_NETDEV_DBG(netdev, "Unknown event %ld "
  1501. "from netdev netlink\n", event);
  1502. }
  1503. if (link_possible && !fcoe_link_ok(lp))
  1504. fcoe_ctlr_link_up(&fcoe->ctlr);
  1505. else if (fcoe_ctlr_link_down(&fcoe->ctlr)) {
  1506. stats = fc_lport_get_stats(lp);
  1507. stats->LinkFailureCount++;
  1508. fcoe_clean_pending_queue(lp);
  1509. }
  1510. out:
  1511. return rc;
  1512. }
  1513. /**
  1514. * fcoe_if_to_netdev() - parse a name buffer to get netdev
  1515. * @buffer: incoming buffer to be copied
  1516. *
  1517. * Returns: NULL or ptr to net_device
  1518. */
  1519. static struct net_device *fcoe_if_to_netdev(const char *buffer)
  1520. {
  1521. char *cp;
  1522. char ifname[IFNAMSIZ + 2];
  1523. if (buffer) {
  1524. strlcpy(ifname, buffer, IFNAMSIZ);
  1525. cp = ifname + strlen(ifname);
  1526. while (--cp >= ifname && *cp == '\n')
  1527. *cp = '\0';
  1528. return dev_get_by_name(&init_net, ifname);
  1529. }
  1530. return NULL;
  1531. }
  1532. /**
  1533. * fcoe_destroy() - handles the destroy from sysfs
  1534. * @buffer: expected to be an eth if name
  1535. * @kp: associated kernel param
  1536. *
  1537. * Returns: 0 for success
  1538. */
  1539. static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
  1540. {
  1541. struct fcoe_interface *fcoe;
  1542. struct net_device *netdev;
  1543. int rc = 0;
  1544. mutex_lock(&fcoe_config_mutex);
  1545. #ifdef CONFIG_FCOE_MODULE
  1546. /*
  1547. * Make sure the module has been initialized, and is not about to be
  1548. * removed. Module paramter sysfs files are writable before the
  1549. * module_init function is called and after module_exit.
  1550. */
  1551. if (THIS_MODULE->state != MODULE_STATE_LIVE) {
  1552. rc = -ENODEV;
  1553. goto out_nodev;
  1554. }
  1555. #endif
  1556. netdev = fcoe_if_to_netdev(buffer);
  1557. if (!netdev) {
  1558. rc = -ENODEV;
  1559. goto out_nodev;
  1560. }
  1561. rtnl_lock();
  1562. fcoe = fcoe_hostlist_lookup_port(netdev);
  1563. if (!fcoe) {
  1564. rtnl_unlock();
  1565. rc = -ENODEV;
  1566. goto out_putdev;
  1567. }
  1568. list_del(&fcoe->list);
  1569. fcoe_interface_cleanup(fcoe);
  1570. rtnl_unlock();
  1571. fcoe_if_destroy(fcoe->ctlr.lp);
  1572. out_putdev:
  1573. dev_put(netdev);
  1574. out_nodev:
  1575. mutex_unlock(&fcoe_config_mutex);
  1576. return rc;
  1577. }
  1578. static void fcoe_destroy_work(struct work_struct *work)
  1579. {
  1580. struct fcoe_port *port;
  1581. port = container_of(work, struct fcoe_port, destroy_work);
  1582. mutex_lock(&fcoe_config_mutex);
  1583. fcoe_if_destroy(port->lport);
  1584. mutex_unlock(&fcoe_config_mutex);
  1585. }
  1586. /**
  1587. * fcoe_create() - Handles the create call from sysfs
  1588. * @buffer: expected to be an eth if name
  1589. * @kp: associated kernel param
  1590. *
  1591. * Returns: 0 for success
  1592. */
  1593. static int fcoe_create(const char *buffer, struct kernel_param *kp)
  1594. {
  1595. int rc;
  1596. struct fcoe_interface *fcoe;
  1597. struct fc_lport *lport;
  1598. struct net_device *netdev;
  1599. mutex_lock(&fcoe_config_mutex);
  1600. #ifdef CONFIG_FCOE_MODULE
  1601. /*
  1602. * Make sure the module has been initialized, and is not about to be
  1603. * removed. Module paramter sysfs files are writable before the
  1604. * module_init function is called and after module_exit.
  1605. */
  1606. if (THIS_MODULE->state != MODULE_STATE_LIVE) {
  1607. rc = -ENODEV;
  1608. goto out_nodev;
  1609. }
  1610. #endif
  1611. rtnl_lock();
  1612. netdev = fcoe_if_to_netdev(buffer);
  1613. if (!netdev) {
  1614. rc = -ENODEV;
  1615. goto out_nodev;
  1616. }
  1617. /* look for existing lport */
  1618. if (fcoe_hostlist_lookup(netdev)) {
  1619. rc = -EEXIST;
  1620. goto out_putdev;
  1621. }
  1622. fcoe = fcoe_interface_create(netdev);
  1623. if (!fcoe) {
  1624. rc = -ENOMEM;
  1625. goto out_putdev;
  1626. }
  1627. lport = fcoe_if_create(fcoe, &netdev->dev, 0);
  1628. if (IS_ERR(lport)) {
  1629. printk(KERN_ERR "fcoe: Failed to create interface (%s)\n",
  1630. netdev->name);
  1631. rc = -EIO;
  1632. fcoe_interface_cleanup(fcoe);
  1633. goto out_free;
  1634. }
  1635. /* Make this the "master" N_Port */
  1636. fcoe->ctlr.lp = lport;
  1637. /* add to lports list */
  1638. fcoe_hostlist_add(lport);
  1639. /* start FIP Discovery and FLOGI */
  1640. lport->boot_time = jiffies;
  1641. fc_fabric_login(lport);
  1642. if (!fcoe_link_ok(lport))
  1643. fcoe_ctlr_link_up(&fcoe->ctlr);
  1644. rc = 0;
  1645. out_free:
  1646. /*
  1647. * Release from init in fcoe_interface_create(), on success lport
  1648. * should be holding a reference taken in fcoe_if_create().
  1649. */
  1650. fcoe_interface_put(fcoe);
  1651. out_putdev:
  1652. dev_put(netdev);
  1653. out_nodev:
  1654. rtnl_unlock();
  1655. mutex_unlock(&fcoe_config_mutex);
  1656. return rc;
  1657. }
  1658. module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR);
  1659. __MODULE_PARM_TYPE(create, "string");
  1660. MODULE_PARM_DESC(create, "Create fcoe fcoe using net device passed in.");
  1661. module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR);
  1662. __MODULE_PARM_TYPE(destroy, "string");
  1663. MODULE_PARM_DESC(destroy, "Destroy fcoe fcoe");
  1664. /**
  1665. * fcoe_link_ok() - Check if link is ok for the fc_lport
  1666. * @lp: ptr to the fc_lport
  1667. *
  1668. * Any permanently-disqualifying conditions have been previously checked.
  1669. * This also updates the speed setting, which may change with link for 100/1000.
  1670. *
  1671. * This function should probably be checking for PAUSE support at some point
  1672. * in the future. Currently Per-priority-pause is not determinable using
  1673. * ethtool, so we shouldn't be restrictive until that problem is resolved.
  1674. *
  1675. * Returns: 0 if link is OK for use by FCoE.
  1676. *
  1677. */
  1678. int fcoe_link_ok(struct fc_lport *lp)
  1679. {
  1680. struct fcoe_port *port = lport_priv(lp);
  1681. struct net_device *dev = port->fcoe->netdev;
  1682. struct ethtool_cmd ecmd = { ETHTOOL_GSET };
  1683. if ((dev->flags & IFF_UP) && netif_carrier_ok(dev) &&
  1684. (!dev_ethtool_get_settings(dev, &ecmd))) {
  1685. lp->link_supported_speeds &=
  1686. ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
  1687. if (ecmd.supported & (SUPPORTED_1000baseT_Half |
  1688. SUPPORTED_1000baseT_Full))
  1689. lp->link_supported_speeds |= FC_PORTSPEED_1GBIT;
  1690. if (ecmd.supported & SUPPORTED_10000baseT_Full)
  1691. lp->link_supported_speeds |=
  1692. FC_PORTSPEED_10GBIT;
  1693. if (ecmd.speed == SPEED_1000)
  1694. lp->link_speed = FC_PORTSPEED_1GBIT;
  1695. if (ecmd.speed == SPEED_10000)
  1696. lp->link_speed = FC_PORTSPEED_10GBIT;
  1697. return 0;
  1698. }
  1699. return -1;
  1700. }
  1701. /**
  1702. * fcoe_percpu_clean() - Clear the pending skbs for an lport
  1703. * @lp: the fc_lport
  1704. *
  1705. * Must be called with fcoe_create_mutex held to single-thread completion.
  1706. *
  1707. * This flushes the pending skbs by adding a new skb to each queue and
  1708. * waiting until they are all freed. This assures us that not only are
  1709. * there no packets that will be handled by the lport, but also that any
  1710. * threads already handling packet have returned.
  1711. */
  1712. void fcoe_percpu_clean(struct fc_lport *lp)
  1713. {
  1714. struct fcoe_percpu_s *pp;
  1715. struct fcoe_rcv_info *fr;
  1716. struct sk_buff_head *list;
  1717. struct sk_buff *skb, *next;
  1718. struct sk_buff *head;
  1719. unsigned int cpu;
  1720. for_each_possible_cpu(cpu) {
  1721. pp = &per_cpu(fcoe_percpu, cpu);
  1722. spin_lock_bh(&pp->fcoe_rx_list.lock);
  1723. list = &pp->fcoe_rx_list;
  1724. head = list->next;
  1725. for (skb = head; skb != (struct sk_buff *)list;
  1726. skb = next) {
  1727. next = skb->next;
  1728. fr = fcoe_dev_from_skb(skb);
  1729. if (fr->fr_dev == lp) {
  1730. __skb_unlink(skb, list);
  1731. kfree_skb(skb);
  1732. }
  1733. }
  1734. if (!pp->thread || !cpu_online(cpu)) {
  1735. spin_unlock_bh(&pp->fcoe_rx_list.lock);
  1736. continue;
  1737. }
  1738. skb = dev_alloc_skb(0);
  1739. if (!skb) {
  1740. spin_unlock_bh(&pp->fcoe_rx_list.lock);
  1741. continue;
  1742. }
  1743. skb->destructor = fcoe_percpu_flush_done;
  1744. __skb_queue_tail(&pp->fcoe_rx_list, skb);
  1745. if (pp->fcoe_rx_list.qlen == 1)
  1746. wake_up_process(pp->thread);
  1747. spin_unlock_bh(&pp->fcoe_rx_list.lock);
  1748. wait_for_completion(&fcoe_flush_completion);
  1749. }
  1750. }
  1751. /**
  1752. * fcoe_clean_pending_queue() - Dequeue a skb and free it
  1753. * @lp: the corresponding fc_lport
  1754. *
  1755. * Returns: none
  1756. */
  1757. void fcoe_clean_pending_queue(struct fc_lport *lp)
  1758. {
  1759. struct fcoe_port *port = lport_priv(lp);
  1760. struct sk_buff *skb;
  1761. spin_lock_bh(&port->fcoe_pending_queue.lock);
  1762. while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) {
  1763. spin_unlock_bh(&port->fcoe_pending_queue.lock);
  1764. kfree_skb(skb);
  1765. spin_lock_bh(&port->fcoe_pending_queue.lock);
  1766. }
  1767. spin_unlock_bh(&port->fcoe_pending_queue.lock);
  1768. }
  1769. /**
  1770. * fcoe_reset() - Resets the fcoe
  1771. * @shost: shost the reset is from
  1772. *
  1773. * Returns: always 0
  1774. */
  1775. int fcoe_reset(struct Scsi_Host *shost)
  1776. {
  1777. struct fc_lport *lport = shost_priv(shost);
  1778. fc_lport_reset(lport);
  1779. return 0;
  1780. }
  1781. /**
  1782. * fcoe_hostlist_lookup_port() - find the corresponding lport by a given device
  1783. * @dev: this is currently ptr to net_device
  1784. *
  1785. * Returns: NULL or the located fcoe_port
  1786. * Locking: must be called with the RNL mutex held
  1787. */
  1788. static struct fcoe_interface *
  1789. fcoe_hostlist_lookup_port(const struct net_device *dev)
  1790. {
  1791. struct fcoe_interface *fcoe;
  1792. list_for_each_entry(fcoe, &fcoe_hostlist, list) {
  1793. if (fcoe->netdev == dev)
  1794. return fcoe;
  1795. }
  1796. return NULL;
  1797. }
  1798. /**
  1799. * fcoe_hostlist_lookup() - Find the corresponding lport by netdev
  1800. * @netdev: ptr to net_device
  1801. *
  1802. * Returns: 0 for success
  1803. * Locking: must be called with the RTNL mutex held
  1804. */
  1805. static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
  1806. {
  1807. struct fcoe_interface *fcoe;
  1808. fcoe = fcoe_hostlist_lookup_port(netdev);
  1809. return (fcoe) ? fcoe->ctlr.lp : NULL;
  1810. }
  1811. /**
  1812. * fcoe_hostlist_add() - Add a lport to lports list
  1813. * @lp: ptr to the fc_lport to be added
  1814. *
  1815. * Returns: 0 for success
  1816. * Locking: must be called with the RTNL mutex held
  1817. */
  1818. static int fcoe_hostlist_add(const struct fc_lport *lport)
  1819. {
  1820. struct fcoe_interface *fcoe;
  1821. struct fcoe_port *port;
  1822. fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport));
  1823. if (!fcoe) {
  1824. port = lport_priv(lport);
  1825. fcoe = port->fcoe;
  1826. list_add_tail(&fcoe->list, &fcoe_hostlist);
  1827. }
  1828. return 0;
  1829. }
  1830. /**
  1831. * fcoe_init() - fcoe module loading initialization
  1832. *
  1833. * Returns 0 on success, negative on failure
  1834. */
  1835. static int __init fcoe_init(void)
  1836. {
  1837. unsigned int cpu;
  1838. int rc = 0;
  1839. struct fcoe_percpu_s *p;
  1840. mutex_lock(&fcoe_config_mutex);
  1841. for_each_possible_cpu(cpu) {
  1842. p = &per_cpu(fcoe_percpu, cpu);
  1843. skb_queue_head_init(&p->fcoe_rx_list);
  1844. }
  1845. for_each_online_cpu(cpu)
  1846. fcoe_percpu_thread_create(cpu);
  1847. /* Initialize per CPU interrupt thread */
  1848. rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
  1849. if (rc)
  1850. goto out_free;
  1851. /* Setup link change notification */
  1852. fcoe_dev_setup();
  1853. rc = fcoe_if_init();
  1854. if (rc)
  1855. goto out_free;
  1856. mutex_unlock(&fcoe_config_mutex);
  1857. return 0;
  1858. out_free:
  1859. for_each_online_cpu(cpu) {
  1860. fcoe_percpu_thread_destroy(cpu);
  1861. }
  1862. mutex_unlock(&fcoe_config_mutex);
  1863. return rc;
  1864. }
  1865. module_init(fcoe_init);
  1866. /**
  1867. * fcoe_exit() - fcoe module unloading cleanup
  1868. *
  1869. * Returns 0 on success, negative on failure
  1870. */
  1871. static void __exit fcoe_exit(void)
  1872. {
  1873. unsigned int cpu;
  1874. struct fcoe_interface *fcoe, *tmp;
  1875. struct fcoe_port *port;
  1876. mutex_lock(&fcoe_config_mutex);
  1877. fcoe_dev_cleanup();
  1878. /* releases the associated fcoe hosts */
  1879. rtnl_lock();
  1880. list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) {
  1881. list_del(&fcoe->list);
  1882. port = lport_priv(fcoe->ctlr.lp);
  1883. fcoe_interface_cleanup(fcoe);
  1884. schedule_work(&port->destroy_work);
  1885. }
  1886. rtnl_unlock();
  1887. unregister_hotcpu_notifier(&fcoe_cpu_notifier);
  1888. for_each_online_cpu(cpu)
  1889. fcoe_percpu_thread_destroy(cpu);
  1890. mutex_unlock(&fcoe_config_mutex);
  1891. /* flush any asyncronous interface destroys,
  1892. * this should happen after the netdev notifier is unregistered */
  1893. flush_scheduled_work();
  1894. /* That will flush out all the N_Ports on the hostlist, but now we
  1895. * may have NPIV VN_Ports scheduled for destruction */
  1896. flush_scheduled_work();
  1897. /* detach from scsi transport
  1898. * must happen after all destroys are done, therefor after the flush */
  1899. fcoe_if_exit();
  1900. }
  1901. module_exit(fcoe_exit);
  1902. /**
  1903. * fcoe_flogi_resp() - FCoE specific FLOGI and FDISC response handler
  1904. * @seq: active sequence in the FLOGI or FDISC exchange
  1905. * @fp: response frame, or error encoded in a pointer (timeout)
  1906. * @arg: pointer the the fcoe_ctlr structure
  1907. *
  1908. * This handles MAC address managment for FCoE, then passes control on to
  1909. * the libfc FLOGI response handler.
  1910. */
  1911. static void fcoe_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
  1912. {
  1913. struct fcoe_ctlr *fip = arg;
  1914. struct fc_exch *exch = fc_seq_exch(seq);
  1915. struct fc_lport *lport = exch->lp;
  1916. u8 *mac;
  1917. if (IS_ERR(fp))
  1918. goto done;
  1919. mac = fr_cb(fp)->granted_mac;
  1920. if (is_zero_ether_addr(mac)) {
  1921. /* pre-FIP */
  1922. mac = eth_hdr(&fp->skb)->h_source;
  1923. if (fcoe_ctlr_recv_flogi(fip, lport, fp, mac)) {
  1924. fc_frame_free(fp);
  1925. return;
  1926. }
  1927. } else {
  1928. /* FIP, libfcoe has already seen it */
  1929. fip->update_mac(lport, fr_cb(fp)->granted_mac);
  1930. }
  1931. done:
  1932. fc_lport_flogi_resp(seq, fp, lport);
  1933. }
  1934. /**
  1935. * fcoe_logo_resp() - FCoE specific LOGO response handler
  1936. * @seq: active sequence in the LOGO exchange
  1937. * @fp: response frame, or error encoded in a pointer (timeout)
  1938. * @arg: pointer the the fcoe_ctlr structure
  1939. *
  1940. * This handles MAC address managment for FCoE, then passes control on to
  1941. * the libfc LOGO response handler.
  1942. */
  1943. static void fcoe_logo_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
  1944. {
  1945. struct fcoe_ctlr *fip = arg;
  1946. struct fc_exch *exch = fc_seq_exch(seq);
  1947. struct fc_lport *lport = exch->lp;
  1948. static u8 zero_mac[ETH_ALEN] = { 0 };
  1949. if (!IS_ERR(fp))
  1950. fip->update_mac(lport, zero_mac);
  1951. fc_lport_logo_resp(seq, fp, lport);
  1952. }
  1953. /**
  1954. * fcoe_elsct_send - FCoE specific ELS handler
  1955. *
  1956. * This does special case handling of FIP encapsualted ELS exchanges for FCoE,
  1957. * using FCoE specific response handlers and passing the FIP controller as
  1958. * the argument (the lport is still available from the exchange).
  1959. *
  1960. * Most of the work here is just handed off to the libfc routine.
  1961. */
  1962. static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport,
  1963. u32 did, struct fc_frame *fp, unsigned int op,
  1964. void (*resp)(struct fc_seq *, struct fc_frame *, void *),
  1965. void *arg, u32 timeout)
  1966. {
  1967. struct fcoe_port *port = lport_priv(lport);
  1968. struct fcoe_interface *fcoe = port->fcoe;
  1969. struct fcoe_ctlr *fip = &fcoe->ctlr;
  1970. struct fc_frame_header *fh = fc_frame_header_get(fp);
  1971. switch (op) {
  1972. case ELS_FLOGI:
  1973. case ELS_FDISC:
  1974. return fc_elsct_send(lport, did, fp, op, fcoe_flogi_resp,
  1975. fip, timeout);
  1976. case ELS_LOGO:
  1977. /* only hook onto fabric logouts, not port logouts */
  1978. if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI)
  1979. break;
  1980. return fc_elsct_send(lport, did, fp, op, fcoe_logo_resp,
  1981. fip, timeout);
  1982. }
  1983. return fc_elsct_send(lport, did, fp, op, resp, arg, timeout);
  1984. }
  1985. /**
  1986. * fcoe_vport_create() - create an fc_host/scsi_host for a vport
  1987. * @vport: fc_vport object to create a new fc_host for
  1988. * @disabled: start the new fc_host in a disabled state by default?
  1989. *
  1990. * Returns: 0 for success
  1991. */
  1992. static int fcoe_vport_create(struct fc_vport *vport, bool disabled)
  1993. {
  1994. struct Scsi_Host *shost = vport_to_shost(vport);
  1995. struct fc_lport *n_port = shost_priv(shost);
  1996. struct fcoe_port *port = lport_priv(n_port);
  1997. struct fcoe_interface *fcoe = port->fcoe;
  1998. struct net_device *netdev = fcoe->netdev;
  1999. struct fc_lport *vn_port;
  2000. mutex_lock(&fcoe_config_mutex);
  2001. vn_port = fcoe_if_create(fcoe, &vport->dev, 1);
  2002. mutex_unlock(&fcoe_config_mutex);
  2003. if (IS_ERR(vn_port)) {
  2004. printk(KERN_ERR "fcoe: fcoe_vport_create(%s) failed\n",
  2005. netdev->name);
  2006. return -EIO;
  2007. }
  2008. if (disabled) {
  2009. fc_vport_set_state(vport, FC_VPORT_DISABLED);
  2010. } else {
  2011. vn_port->boot_time = jiffies;
  2012. fc_fabric_login(vn_port);
  2013. fc_vport_setlink(vn_port);
  2014. }
  2015. return 0;
  2016. }
  2017. /**
  2018. * fcoe_vport_destroy() - destroy the fc_host/scsi_host for a vport
  2019. * @vport: fc_vport object that is being destroyed
  2020. *
  2021. * Returns: 0 for success
  2022. */
  2023. static int fcoe_vport_destroy(struct fc_vport *vport)
  2024. {
  2025. struct Scsi_Host *shost = vport_to_shost(vport);
  2026. struct fc_lport *n_port = shost_priv(shost);
  2027. struct fc_lport *vn_port = vport->dd_data;
  2028. struct fcoe_port *port = lport_priv(vn_port);
  2029. mutex_lock(&n_port->lp_mutex);
  2030. list_del(&vn_port->list);
  2031. mutex_unlock(&n_port->lp_mutex);
  2032. schedule_work(&port->destroy_work);
  2033. return 0;
  2034. }
  2035. /**
  2036. * fcoe_vport_disable() - change vport state
  2037. * @vport: vport to bring online/offline
  2038. * @disable: should the vport be disabled?
  2039. */
  2040. static int fcoe_vport_disable(struct fc_vport *vport, bool disable)
  2041. {
  2042. struct fc_lport *lport = vport->dd_data;
  2043. if (disable) {
  2044. fc_vport_set_state(vport, FC_VPORT_DISABLED);
  2045. fc_fabric_logoff(lport);
  2046. } else {
  2047. lport->boot_time = jiffies;
  2048. fc_fabric_login(lport);
  2049. fc_vport_setlink(lport);
  2050. }
  2051. return 0;
  2052. }
  2053. /**
  2054. * fcoe_vport_set_symbolic_name() - append vport string to symbolic name
  2055. * @vport: fc_vport with a new symbolic name string
  2056. *
  2057. * After generating a new symbolic name string, a new RSPN_ID request is
  2058. * sent to the name server. There is no response handler, so if it fails
  2059. * for some reason it will not be retried.
  2060. */
  2061. static void fcoe_set_vport_symbolic_name(struct fc_vport *vport)
  2062. {
  2063. struct fc_lport *lport = vport->dd_data;
  2064. struct fc_frame *fp;
  2065. size_t len;
  2066. snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE,
  2067. "%s v%s over %s : %s", FCOE_NAME, FCOE_VERSION,
  2068. fcoe_netdev(lport)->name, vport->symbolic_name);
  2069. if (lport->state != LPORT_ST_READY)
  2070. return;
  2071. len = strnlen(fc_host_symbolic_name(lport->host), 255);
  2072. fp = fc_frame_alloc(lport,
  2073. sizeof(struct fc_ct_hdr) +
  2074. sizeof(struct fc_ns_rspn) + len);
  2075. if (!fp)
  2076. return;
  2077. lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSPN_ID,
  2078. NULL, NULL, lport->e_d_tov);
  2079. }