fcoe.c 61 KB

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