fcoe.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863
  1. /*
  2. * Copyright(c) 2007 - 2008 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. static int debug_fcoe;
  44. MODULE_AUTHOR("Open-FCoE.org");
  45. MODULE_DESCRIPTION("FCoE");
  46. MODULE_LICENSE("GPL v2");
  47. /* fcoe host list */
  48. LIST_HEAD(fcoe_hostlist);
  49. DEFINE_RWLOCK(fcoe_hostlist_lock);
  50. DEFINE_TIMER(fcoe_timer, NULL, 0, 0);
  51. DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
  52. /* Function Prototypes */
  53. static int fcoe_reset(struct Scsi_Host *shost);
  54. static int fcoe_xmit(struct fc_lport *, struct fc_frame *);
  55. static int fcoe_rcv(struct sk_buff *, struct net_device *,
  56. struct packet_type *, struct net_device *);
  57. static int fcoe_percpu_receive_thread(void *arg);
  58. static void fcoe_clean_pending_queue(struct fc_lport *lp);
  59. static void fcoe_percpu_clean(struct fc_lport *lp);
  60. static int fcoe_link_ok(struct fc_lport *lp);
  61. static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
  62. static int fcoe_hostlist_add(const struct fc_lport *);
  63. static int fcoe_hostlist_remove(const struct fc_lport *);
  64. static int fcoe_check_wait_queue(struct fc_lport *);
  65. static int fcoe_device_notification(struct notifier_block *, ulong, void *);
  66. static void fcoe_dev_setup(void);
  67. static void fcoe_dev_cleanup(void);
  68. /* notification function from net device */
  69. static struct notifier_block fcoe_notifier = {
  70. .notifier_call = fcoe_device_notification,
  71. };
  72. static struct scsi_transport_template *scsi_transport_fcoe_sw;
  73. struct fc_function_template fcoe_transport_function = {
  74. .show_host_node_name = 1,
  75. .show_host_port_name = 1,
  76. .show_host_supported_classes = 1,
  77. .show_host_supported_fc4s = 1,
  78. .show_host_active_fc4s = 1,
  79. .show_host_maxframe_size = 1,
  80. .show_host_port_id = 1,
  81. .show_host_supported_speeds = 1,
  82. .get_host_speed = fc_get_host_speed,
  83. .show_host_speed = 1,
  84. .show_host_port_type = 1,
  85. .get_host_port_state = fc_get_host_port_state,
  86. .show_host_port_state = 1,
  87. .show_host_symbolic_name = 1,
  88. .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
  89. .show_rport_maxframe_size = 1,
  90. .show_rport_supported_classes = 1,
  91. .show_host_fabric_name = 1,
  92. .show_starget_node_name = 1,
  93. .show_starget_port_name = 1,
  94. .show_starget_port_id = 1,
  95. .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
  96. .show_rport_dev_loss_tmo = 1,
  97. .get_fc_host_stats = fc_get_host_stats,
  98. .issue_fc_host_lip = fcoe_reset,
  99. .terminate_rport_io = fc_rport_terminate_io,
  100. };
  101. static struct scsi_host_template fcoe_shost_template = {
  102. .module = THIS_MODULE,
  103. .name = "FCoE Driver",
  104. .proc_name = FCOE_NAME,
  105. .queuecommand = fc_queuecommand,
  106. .eh_abort_handler = fc_eh_abort,
  107. .eh_device_reset_handler = fc_eh_device_reset,
  108. .eh_host_reset_handler = fc_eh_host_reset,
  109. .slave_alloc = fc_slave_alloc,
  110. .change_queue_depth = fc_change_queue_depth,
  111. .change_queue_type = fc_change_queue_type,
  112. .this_id = -1,
  113. .cmd_per_lun = 32,
  114. .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
  115. .use_clustering = ENABLE_CLUSTERING,
  116. .sg_tablesize = SG_ALL,
  117. .max_sectors = 0xffff,
  118. };
  119. /**
  120. * fcoe_lport_config() - sets up the fc_lport
  121. * @lp: ptr to the fc_lport
  122. *
  123. * Returns: 0 for success
  124. */
  125. static int fcoe_lport_config(struct fc_lport *lp)
  126. {
  127. lp->link_up = 0;
  128. lp->qfull = 0;
  129. lp->max_retry_count = 3;
  130. lp->e_d_tov = 2 * 1000; /* FC-FS default */
  131. lp->r_a_tov = 2 * 2 * 1000;
  132. lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
  133. FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
  134. fc_lport_init_stats(lp);
  135. /* lport fc_lport related configuration */
  136. fc_lport_config(lp);
  137. /* offload related configuration */
  138. lp->crc_offload = 0;
  139. lp->seq_offload = 0;
  140. lp->lro_enabled = 0;
  141. lp->lro_xid = 0;
  142. lp->lso_max = 0;
  143. return 0;
  144. }
  145. /**
  146. * fcoe_netdev_config() - Set up netdev for SW FCoE
  147. * @lp : ptr to the fc_lport
  148. * @netdev : ptr to the associated netdevice struct
  149. *
  150. * Must be called after fcoe_lport_config() as it will use lport mutex
  151. *
  152. * Returns : 0 for success
  153. */
  154. static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
  155. {
  156. u32 mfs;
  157. u64 wwnn, wwpn;
  158. struct fcoe_softc *fc;
  159. u8 flogi_maddr[ETH_ALEN];
  160. /* Setup lport private data to point to fcoe softc */
  161. fc = lport_priv(lp);
  162. fc->ctlr.lp = lp;
  163. fc->real_dev = netdev;
  164. fc->phys_dev = netdev;
  165. /* Require support for get_pauseparam ethtool op. */
  166. if (netdev->priv_flags & IFF_802_1Q_VLAN)
  167. fc->phys_dev = vlan_dev_real_dev(netdev);
  168. /* Do not support for bonding device */
  169. if ((fc->real_dev->priv_flags & IFF_MASTER_ALB) ||
  170. (fc->real_dev->priv_flags & IFF_SLAVE_INACTIVE) ||
  171. (fc->real_dev->priv_flags & IFF_MASTER_8023AD)) {
  172. return -EOPNOTSUPP;
  173. }
  174. /*
  175. * Determine max frame size based on underlying device and optional
  176. * user-configured limit. If the MFS is too low, fcoe_link_ok()
  177. * will return 0, so do this first.
  178. */
  179. mfs = fc->real_dev->mtu - (sizeof(struct fcoe_hdr) +
  180. sizeof(struct fcoe_crc_eof));
  181. if (fc_set_mfs(lp, mfs))
  182. return -EINVAL;
  183. /* offload features support */
  184. if (fc->real_dev->features & NETIF_F_SG)
  185. lp->sg_supp = 1;
  186. #ifdef NETIF_F_FCOE_CRC
  187. if (netdev->features & NETIF_F_FCOE_CRC) {
  188. lp->crc_offload = 1;
  189. printk(KERN_DEBUG "fcoe:%s supports FCCRC offload\n",
  190. netdev->name);
  191. }
  192. #endif
  193. #ifdef NETIF_F_FSO
  194. if (netdev->features & NETIF_F_FSO) {
  195. lp->seq_offload = 1;
  196. lp->lso_max = netdev->gso_max_size;
  197. printk(KERN_DEBUG "fcoe:%s supports LSO for max len 0x%x\n",
  198. netdev->name, lp->lso_max);
  199. }
  200. #endif
  201. if (netdev->fcoe_ddp_xid) {
  202. lp->lro_enabled = 1;
  203. lp->lro_xid = netdev->fcoe_ddp_xid;
  204. printk(KERN_DEBUG "fcoe:%s supports LRO for max xid 0x%x\n",
  205. netdev->name, lp->lro_xid);
  206. }
  207. skb_queue_head_init(&fc->fcoe_pending_queue);
  208. fc->fcoe_pending_queue_active = 0;
  209. /* setup Source Mac Address */
  210. memcpy(fc->ctlr.ctl_src_addr, fc->real_dev->dev_addr,
  211. fc->real_dev->addr_len);
  212. wwnn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 1, 0);
  213. fc_set_wwnn(lp, wwnn);
  214. /* XXX - 3rd arg needs to be vlan id */
  215. wwpn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 2, 0);
  216. fc_set_wwpn(lp, wwpn);
  217. /*
  218. * Add FCoE MAC address as second unicast MAC address
  219. * or enter promiscuous mode if not capable of listening
  220. * for multiple unicast MACs.
  221. */
  222. rtnl_lock();
  223. memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
  224. dev_unicast_add(fc->real_dev, flogi_maddr, ETH_ALEN);
  225. dev_mc_add(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
  226. rtnl_unlock();
  227. /*
  228. * setup the receive function from ethernet driver
  229. * on the ethertype for the given device
  230. */
  231. fc->fcoe_packet_type.func = fcoe_rcv;
  232. fc->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
  233. fc->fcoe_packet_type.dev = fc->real_dev;
  234. dev_add_pack(&fc->fcoe_packet_type);
  235. return 0;
  236. }
  237. /**
  238. * fcoe_shost_config() - Sets up fc_lport->host
  239. * @lp : ptr to the fc_lport
  240. * @shost : ptr to the associated scsi host
  241. * @dev : device associated to scsi host
  242. *
  243. * Must be called after fcoe_lport_config() and fcoe_netdev_config()
  244. *
  245. * Returns : 0 for success
  246. */
  247. static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
  248. struct device *dev)
  249. {
  250. int rc = 0;
  251. /* lport scsi host config */
  252. lp->host = shost;
  253. lp->host->max_lun = FCOE_MAX_LUN;
  254. lp->host->max_id = FCOE_MAX_FCP_TARGET;
  255. lp->host->max_channel = 0;
  256. lp->host->transportt = scsi_transport_fcoe_sw;
  257. /* add the new host to the SCSI-ml */
  258. rc = scsi_add_host(lp->host, dev);
  259. if (rc) {
  260. FC_DBG("fcoe_shost_config:error on scsi_add_host\n");
  261. return rc;
  262. }
  263. sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s",
  264. FCOE_NAME, FCOE_VERSION,
  265. fcoe_netdev(lp)->name);
  266. return 0;
  267. }
  268. /**
  269. * fcoe_em_config() - allocates em for this lport
  270. * @lp: the port that em is to allocated for
  271. *
  272. * Returns : 0 on success
  273. */
  274. static inline int fcoe_em_config(struct fc_lport *lp)
  275. {
  276. BUG_ON(lp->emp);
  277. lp->emp = fc_exch_mgr_alloc(lp, FC_CLASS_3,
  278. FCOE_MIN_XID, FCOE_MAX_XID);
  279. if (!lp->emp)
  280. return -ENOMEM;
  281. return 0;
  282. }
  283. /**
  284. * fcoe_if_destroy() - FCoE software HBA tear-down function
  285. * @netdev: ptr to the associated net_device
  286. *
  287. * Returns: 0 if link is OK for use by FCoE.
  288. */
  289. static int fcoe_if_destroy(struct net_device *netdev)
  290. {
  291. struct fc_lport *lp = NULL;
  292. struct fcoe_softc *fc;
  293. u8 flogi_maddr[ETH_ALEN];
  294. BUG_ON(!netdev);
  295. printk(KERN_DEBUG "fcoe_if_destroy:interface on %s\n",
  296. netdev->name);
  297. lp = fcoe_hostlist_lookup(netdev);
  298. if (!lp)
  299. return -ENODEV;
  300. fc = lport_priv(lp);
  301. /* Logout of the fabric */
  302. fc_fabric_logoff(lp);
  303. /* Remove the instance from fcoe's list */
  304. fcoe_hostlist_remove(lp);
  305. /* Don't listen for Ethernet packets anymore */
  306. dev_remove_pack(&fc->fcoe_packet_type);
  307. dev_remove_pack(&fc->fip_packet_type);
  308. fcoe_ctlr_destroy(&fc->ctlr);
  309. /* Cleanup the fc_lport */
  310. fc_lport_destroy(lp);
  311. fc_fcp_destroy(lp);
  312. /* Detach from the scsi-ml */
  313. fc_remove_host(lp->host);
  314. scsi_remove_host(lp->host);
  315. /* There are no more rports or I/O, free the EM */
  316. if (lp->emp)
  317. fc_exch_mgr_free(lp->emp);
  318. /* Delete secondary MAC addresses */
  319. rtnl_lock();
  320. memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
  321. dev_unicast_delete(fc->real_dev, flogi_maddr, ETH_ALEN);
  322. if (!is_zero_ether_addr(fc->ctlr.data_src_addr))
  323. dev_unicast_delete(fc->real_dev,
  324. fc->ctlr.data_src_addr, ETH_ALEN);
  325. dev_mc_delete(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
  326. rtnl_unlock();
  327. /* Free the per-CPU receive threads */
  328. fcoe_percpu_clean(lp);
  329. /* Free existing skbs */
  330. fcoe_clean_pending_queue(lp);
  331. /* Free memory used by statistical counters */
  332. fc_lport_free_stats(lp);
  333. /* Release the net_device and Scsi_Host */
  334. dev_put(fc->real_dev);
  335. scsi_host_put(lp->host);
  336. return 0;
  337. }
  338. /*
  339. * fcoe_ddp_setup - calls LLD's ddp_setup through net_device
  340. * @lp: the corresponding fc_lport
  341. * @xid: the exchange id for this ddp transfer
  342. * @sgl: the scatterlist describing this transfer
  343. * @sgc: number of sg items
  344. *
  345. * Returns : 0 no ddp
  346. */
  347. static int fcoe_ddp_setup(struct fc_lport *lp, u16 xid,
  348. struct scatterlist *sgl, unsigned int sgc)
  349. {
  350. struct net_device *n = fcoe_netdev(lp);
  351. if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_setup)
  352. return n->netdev_ops->ndo_fcoe_ddp_setup(n, xid, sgl, sgc);
  353. return 0;
  354. }
  355. /*
  356. * fcoe_ddp_done - calls LLD's ddp_done through net_device
  357. * @lp: the corresponding fc_lport
  358. * @xid: the exchange id for this ddp transfer
  359. *
  360. * Returns : the length of data that have been completed by ddp
  361. */
  362. static int fcoe_ddp_done(struct fc_lport *lp, u16 xid)
  363. {
  364. struct net_device *n = fcoe_netdev(lp);
  365. if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_done)
  366. return n->netdev_ops->ndo_fcoe_ddp_done(n, xid);
  367. return 0;
  368. }
  369. static struct libfc_function_template fcoe_libfc_fcn_templ = {
  370. .frame_send = fcoe_xmit,
  371. .ddp_setup = fcoe_ddp_setup,
  372. .ddp_done = fcoe_ddp_done,
  373. };
  374. /**
  375. * fcoe_fip_recv - handle a received FIP frame.
  376. * @skb: the receive skb
  377. * @dev: associated &net_device
  378. * @ptype: the &packet_type structure which was used to register this handler.
  379. * @orig_dev: original receive &net_device, in case @dev is a bond.
  380. *
  381. * Returns: 0 for success
  382. */
  383. static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
  384. struct packet_type *ptype,
  385. struct net_device *orig_dev)
  386. {
  387. struct fcoe_softc *fc;
  388. fc = container_of(ptype, struct fcoe_softc, fip_packet_type);
  389. fcoe_ctlr_recv(&fc->ctlr, skb);
  390. return 0;
  391. }
  392. /**
  393. * fcoe_fip_send() - send an Ethernet-encapsulated FIP frame.
  394. * @fip: FCoE controller.
  395. * @skb: FIP Packet.
  396. */
  397. static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
  398. {
  399. skb->dev = fcoe_from_ctlr(fip)->real_dev;
  400. dev_queue_xmit(skb);
  401. }
  402. /**
  403. * fcoe_update_src_mac() - Update Ethernet MAC filters.
  404. * @fip: FCoE controller.
  405. * @old: Unicast MAC address to delete if the MAC is non-zero.
  406. * @new: Unicast MAC address to add.
  407. *
  408. * Remove any previously-set unicast MAC filter.
  409. * Add secondary FCoE MAC address filter for our OUI.
  410. */
  411. static void fcoe_update_src_mac(struct fcoe_ctlr *fip, u8 *old, u8 *new)
  412. {
  413. struct fcoe_softc *fc;
  414. fc = fcoe_from_ctlr(fip);
  415. rtnl_lock();
  416. if (!is_zero_ether_addr(old))
  417. dev_unicast_delete(fc->real_dev, old, ETH_ALEN);
  418. dev_unicast_add(fc->real_dev, new, ETH_ALEN);
  419. rtnl_unlock();
  420. }
  421. /**
  422. * fcoe_if_create() - this function creates the fcoe interface
  423. * @netdev: pointer the associated netdevice
  424. *
  425. * Creates fc_lport struct and scsi_host for lport, configures lport
  426. * and starts fabric login.
  427. *
  428. * Returns : 0 on success
  429. */
  430. static int fcoe_if_create(struct net_device *netdev)
  431. {
  432. int rc;
  433. struct fc_lport *lp = NULL;
  434. struct fcoe_softc *fc;
  435. struct Scsi_Host *shost;
  436. BUG_ON(!netdev);
  437. printk(KERN_DEBUG "fcoe_if_create:interface on %s\n",
  438. netdev->name);
  439. lp = fcoe_hostlist_lookup(netdev);
  440. if (lp)
  441. return -EEXIST;
  442. shost = libfc_host_alloc(&fcoe_shost_template,
  443. sizeof(struct fcoe_softc));
  444. if (!shost) {
  445. FC_DBG("Could not allocate host structure\n");
  446. return -ENOMEM;
  447. }
  448. lp = shost_priv(shost);
  449. fc = lport_priv(lp);
  450. /* configure fc_lport, e.g., em */
  451. rc = fcoe_lport_config(lp);
  452. if (rc) {
  453. FC_DBG("Could not configure lport\n");
  454. goto out_host_put;
  455. }
  456. /* configure lport network properties */
  457. rc = fcoe_netdev_config(lp, netdev);
  458. if (rc) {
  459. FC_DBG("Could not configure netdev for lport\n");
  460. goto out_host_put;
  461. }
  462. /*
  463. * Initialize FIP.
  464. */
  465. fcoe_ctlr_init(&fc->ctlr);
  466. fc->ctlr.send = fcoe_fip_send;
  467. fc->ctlr.update_mac = fcoe_update_src_mac;
  468. fc->fip_packet_type.func = fcoe_fip_recv;
  469. fc->fip_packet_type.type = htons(ETH_P_FIP);
  470. fc->fip_packet_type.dev = fc->real_dev;
  471. dev_add_pack(&fc->fip_packet_type);
  472. /* configure lport scsi host properties */
  473. rc = fcoe_shost_config(lp, shost, &netdev->dev);
  474. if (rc) {
  475. FC_DBG("Could not configure shost for lport\n");
  476. goto out_host_put;
  477. }
  478. /* lport exch manager allocation */
  479. rc = fcoe_em_config(lp);
  480. if (rc) {
  481. FC_DBG("Could not configure em for lport\n");
  482. goto out_host_put;
  483. }
  484. /* Initialize the library */
  485. rc = fcoe_libfc_config(lp, &fcoe_libfc_fcn_templ);
  486. if (rc) {
  487. FC_DBG("Could not configure libfc for lport!\n");
  488. goto out_lp_destroy;
  489. }
  490. /* add to lports list */
  491. fcoe_hostlist_add(lp);
  492. lp->boot_time = jiffies;
  493. fc_fabric_login(lp);
  494. if (!fcoe_link_ok(lp))
  495. fcoe_ctlr_link_up(&fc->ctlr);
  496. dev_hold(netdev);
  497. return rc;
  498. out_lp_destroy:
  499. fc_exch_mgr_free(lp->emp); /* Free the EM */
  500. out_host_put:
  501. scsi_host_put(lp->host);
  502. return rc;
  503. }
  504. /**
  505. * fcoe_if_init() - attach to scsi transport
  506. *
  507. * Returns : 0 on success
  508. */
  509. static int __init fcoe_if_init(void)
  510. {
  511. /* attach to scsi transport */
  512. scsi_transport_fcoe_sw =
  513. fc_attach_transport(&fcoe_transport_function);
  514. if (!scsi_transport_fcoe_sw) {
  515. printk(KERN_ERR "fcoe_init:fc_attach_transport() failed\n");
  516. return -ENODEV;
  517. }
  518. return 0;
  519. }
  520. /**
  521. * fcoe_if_exit() - detach from scsi transport
  522. *
  523. * Returns : 0 on success
  524. */
  525. int __exit fcoe_if_exit(void)
  526. {
  527. fc_release_transport(scsi_transport_fcoe_sw);
  528. return 0;
  529. }
  530. /**
  531. * fcoe_percpu_thread_create() - Create a receive thread for an online cpu
  532. * @cpu: cpu index for the online cpu
  533. */
  534. static void fcoe_percpu_thread_create(unsigned int cpu)
  535. {
  536. struct fcoe_percpu_s *p;
  537. struct task_struct *thread;
  538. p = &per_cpu(fcoe_percpu, cpu);
  539. thread = kthread_create(fcoe_percpu_receive_thread,
  540. (void *)p, "fcoethread/%d", cpu);
  541. if (likely(!IS_ERR(p->thread))) {
  542. kthread_bind(thread, cpu);
  543. wake_up_process(thread);
  544. spin_lock_bh(&p->fcoe_rx_list.lock);
  545. p->thread = thread;
  546. spin_unlock_bh(&p->fcoe_rx_list.lock);
  547. }
  548. }
  549. /**
  550. * fcoe_percpu_thread_destroy() - removes the rx thread for the given cpu
  551. * @cpu: cpu index the rx thread is to be removed
  552. *
  553. * Destroys a per-CPU Rx thread. Any pending skbs are moved to the
  554. * current CPU's Rx thread. If the thread being destroyed is bound to
  555. * the CPU processing this context the skbs will be freed.
  556. */
  557. static void fcoe_percpu_thread_destroy(unsigned int cpu)
  558. {
  559. struct fcoe_percpu_s *p;
  560. struct task_struct *thread;
  561. struct page *crc_eof;
  562. struct sk_buff *skb;
  563. #ifdef CONFIG_SMP
  564. struct fcoe_percpu_s *p0;
  565. unsigned targ_cpu = smp_processor_id();
  566. #endif /* CONFIG_SMP */
  567. printk(KERN_DEBUG "fcoe: Destroying receive thread for CPU %d\n", cpu);
  568. /* Prevent any new skbs from being queued for this CPU. */
  569. p = &per_cpu(fcoe_percpu, cpu);
  570. spin_lock_bh(&p->fcoe_rx_list.lock);
  571. thread = p->thread;
  572. p->thread = NULL;
  573. crc_eof = p->crc_eof_page;
  574. p->crc_eof_page = NULL;
  575. p->crc_eof_offset = 0;
  576. spin_unlock_bh(&p->fcoe_rx_list.lock);
  577. #ifdef CONFIG_SMP
  578. /*
  579. * Don't bother moving the skb's if this context is running
  580. * on the same CPU that is having its thread destroyed. This
  581. * can easily happen when the module is removed.
  582. */
  583. if (cpu != targ_cpu) {
  584. p0 = &per_cpu(fcoe_percpu, targ_cpu);
  585. spin_lock_bh(&p0->fcoe_rx_list.lock);
  586. if (p0->thread) {
  587. FC_DBG("Moving frames from CPU %d to CPU %d\n",
  588. cpu, targ_cpu);
  589. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  590. __skb_queue_tail(&p0->fcoe_rx_list, skb);
  591. spin_unlock_bh(&p0->fcoe_rx_list.lock);
  592. } else {
  593. /*
  594. * The targeted CPU is not initialized and cannot accept
  595. * new skbs. Unlock the targeted CPU and drop the skbs
  596. * on the CPU that is going offline.
  597. */
  598. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  599. kfree_skb(skb);
  600. spin_unlock_bh(&p0->fcoe_rx_list.lock);
  601. }
  602. } else {
  603. /*
  604. * This scenario occurs when the module is being removed
  605. * and all threads are being destroyed. skbs will continue
  606. * to be shifted from the CPU thread that is being removed
  607. * to the CPU thread associated with the CPU that is processing
  608. * the module removal. Once there is only one CPU Rx thread it
  609. * will reach this case and we will drop all skbs and later
  610. * stop the thread.
  611. */
  612. spin_lock_bh(&p->fcoe_rx_list.lock);
  613. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  614. kfree_skb(skb);
  615. spin_unlock_bh(&p->fcoe_rx_list.lock);
  616. }
  617. #else
  618. /*
  619. * This a non-SMP scenario where the singular Rx thread is
  620. * being removed. Free all skbs and stop the thread.
  621. */
  622. spin_lock_bh(&p->fcoe_rx_list.lock);
  623. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
  624. kfree_skb(skb);
  625. spin_unlock_bh(&p->fcoe_rx_list.lock);
  626. #endif
  627. if (thread)
  628. kthread_stop(thread);
  629. if (crc_eof)
  630. put_page(crc_eof);
  631. }
  632. /**
  633. * fcoe_cpu_callback() - fcoe cpu hotplug event callback
  634. * @nfb: callback data block
  635. * @action: event triggering the callback
  636. * @hcpu: index for the cpu of this event
  637. *
  638. * This creates or destroys per cpu data for fcoe
  639. *
  640. * Returns NOTIFY_OK always.
  641. */
  642. static int fcoe_cpu_callback(struct notifier_block *nfb,
  643. unsigned long action, void *hcpu)
  644. {
  645. unsigned cpu = (unsigned long)hcpu;
  646. switch (action) {
  647. case CPU_ONLINE:
  648. case CPU_ONLINE_FROZEN:
  649. FC_DBG("CPU %x online: Create Rx thread\n", cpu);
  650. fcoe_percpu_thread_create(cpu);
  651. break;
  652. case CPU_DEAD:
  653. case CPU_DEAD_FROZEN:
  654. FC_DBG("CPU %x offline: Remove Rx thread\n", cpu);
  655. fcoe_percpu_thread_destroy(cpu);
  656. break;
  657. default:
  658. break;
  659. }
  660. return NOTIFY_OK;
  661. }
  662. static struct notifier_block fcoe_cpu_notifier = {
  663. .notifier_call = fcoe_cpu_callback,
  664. };
  665. /**
  666. * fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ
  667. * @skb: the receive skb
  668. * @dev: associated net device
  669. * @ptype: context
  670. * @olddev: last device
  671. *
  672. * this function will receive the packet and build fc frame and pass it up
  673. *
  674. * Returns: 0 for success
  675. */
  676. int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
  677. struct packet_type *ptype, struct net_device *olddev)
  678. {
  679. struct fc_lport *lp;
  680. struct fcoe_rcv_info *fr;
  681. struct fcoe_softc *fc;
  682. struct fc_frame_header *fh;
  683. struct fcoe_percpu_s *fps;
  684. unsigned short oxid;
  685. unsigned int cpu = 0;
  686. fc = container_of(ptype, struct fcoe_softc, fcoe_packet_type);
  687. lp = fc->ctlr.lp;
  688. if (unlikely(lp == NULL)) {
  689. FC_DBG("cannot find hba structure");
  690. goto err2;
  691. }
  692. if (!lp->link_up)
  693. goto err2;
  694. if (unlikely(debug_fcoe)) {
  695. FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p tail:%p "
  696. "end:%p sum:%d dev:%s", skb->len, skb->data_len,
  697. skb->head, skb->data, skb_tail_pointer(skb),
  698. skb_end_pointer(skb), skb->csum,
  699. skb->dev ? skb->dev->name : "<NULL>");
  700. }
  701. /* check for FCOE packet type */
  702. if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
  703. FC_DBG("wrong FC type frame");
  704. goto err;
  705. }
  706. /*
  707. * Check for minimum frame length, and make sure required FCoE
  708. * and FC headers are pulled into the linear data area.
  709. */
  710. if (unlikely((skb->len < FCOE_MIN_FRAME) ||
  711. !pskb_may_pull(skb, FCOE_HEADER_LEN)))
  712. goto err;
  713. skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
  714. fh = (struct fc_frame_header *) skb_transport_header(skb);
  715. oxid = ntohs(fh->fh_ox_id);
  716. fr = fcoe_dev_from_skb(skb);
  717. fr->fr_dev = lp;
  718. fr->ptype = ptype;
  719. #ifdef CONFIG_SMP
  720. /*
  721. * The incoming frame exchange id(oxid) is ANDed with num of online
  722. * cpu bits to get cpu and then this cpu is used for selecting
  723. * a per cpu kernel thread from fcoe_percpu.
  724. */
  725. cpu = oxid & (num_online_cpus() - 1);
  726. #endif
  727. fps = &per_cpu(fcoe_percpu, cpu);
  728. spin_lock_bh(&fps->fcoe_rx_list.lock);
  729. if (unlikely(!fps->thread)) {
  730. /*
  731. * The targeted CPU is not ready, let's target
  732. * the first CPU now. For non-SMP systems this
  733. * will check the same CPU twice.
  734. */
  735. FC_DBG("CPU is online, but no receive thread ready "
  736. "for incoming skb- using first online CPU.\n");
  737. spin_unlock_bh(&fps->fcoe_rx_list.lock);
  738. cpu = first_cpu(cpu_online_map);
  739. fps = &per_cpu(fcoe_percpu, cpu);
  740. spin_lock_bh(&fps->fcoe_rx_list.lock);
  741. if (!fps->thread) {
  742. spin_unlock_bh(&fps->fcoe_rx_list.lock);
  743. goto err;
  744. }
  745. }
  746. /*
  747. * We now have a valid CPU that we're targeting for
  748. * this skb. We also have this receive thread locked,
  749. * so we're free to queue skbs into it's queue.
  750. */
  751. __skb_queue_tail(&fps->fcoe_rx_list, skb);
  752. if (fps->fcoe_rx_list.qlen == 1)
  753. wake_up_process(fps->thread);
  754. spin_unlock_bh(&fps->fcoe_rx_list.lock);
  755. return 0;
  756. err:
  757. fc_lport_get_stats(lp)->ErrorFrames++;
  758. err2:
  759. kfree_skb(skb);
  760. return -1;
  761. }
  762. /**
  763. * fcoe_start_io() - pass to netdev to start xmit for fcoe
  764. * @skb: the skb to be xmitted
  765. *
  766. * Returns: 0 for success
  767. */
  768. static inline int fcoe_start_io(struct sk_buff *skb)
  769. {
  770. int rc;
  771. skb_get(skb);
  772. rc = dev_queue_xmit(skb);
  773. if (rc != 0)
  774. return rc;
  775. kfree_skb(skb);
  776. return 0;
  777. }
  778. /**
  779. * fcoe_get_paged_crc_eof() - in case we need to alloc a page for crc_eof
  780. * @skb: the skb to be xmitted
  781. * @tlen: total len
  782. *
  783. * Returns: 0 for success
  784. */
  785. static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
  786. {
  787. struct fcoe_percpu_s *fps;
  788. struct page *page;
  789. fps = &get_cpu_var(fcoe_percpu);
  790. page = fps->crc_eof_page;
  791. if (!page) {
  792. page = alloc_page(GFP_ATOMIC);
  793. if (!page) {
  794. put_cpu_var(fcoe_percpu);
  795. return -ENOMEM;
  796. }
  797. fps->crc_eof_page = page;
  798. fps->crc_eof_offset = 0;
  799. }
  800. get_page(page);
  801. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
  802. fps->crc_eof_offset, tlen);
  803. skb->len += tlen;
  804. skb->data_len += tlen;
  805. skb->truesize += tlen;
  806. fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
  807. if (fps->crc_eof_offset >= PAGE_SIZE) {
  808. fps->crc_eof_page = NULL;
  809. fps->crc_eof_offset = 0;
  810. put_page(page);
  811. }
  812. put_cpu_var(fcoe_percpu);
  813. return 0;
  814. }
  815. /**
  816. * fcoe_fc_crc() - calculates FC CRC in this fcoe skb
  817. * @fp: the fc_frame containing data to be checksummed
  818. *
  819. * This uses crc32() to calculate the crc for fc frame
  820. * Return : 32 bit crc
  821. */
  822. u32 fcoe_fc_crc(struct fc_frame *fp)
  823. {
  824. struct sk_buff *skb = fp_skb(fp);
  825. struct skb_frag_struct *frag;
  826. unsigned char *data;
  827. unsigned long off, len, clen;
  828. u32 crc;
  829. unsigned i;
  830. crc = crc32(~0, skb->data, skb_headlen(skb));
  831. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  832. frag = &skb_shinfo(skb)->frags[i];
  833. off = frag->page_offset;
  834. len = frag->size;
  835. while (len > 0) {
  836. clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
  837. data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
  838. KM_SKB_DATA_SOFTIRQ);
  839. crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
  840. kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
  841. off += clen;
  842. len -= clen;
  843. }
  844. }
  845. return crc;
  846. }
  847. /**
  848. * fcoe_xmit() - FCoE frame transmit function
  849. * @lp: the associated local port
  850. * @fp: the fc_frame to be transmitted
  851. *
  852. * Return : 0 for success
  853. */
  854. int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
  855. {
  856. int wlen, rc = 0;
  857. u32 crc;
  858. struct ethhdr *eh;
  859. struct fcoe_crc_eof *cp;
  860. struct sk_buff *skb;
  861. struct fcoe_dev_stats *stats;
  862. struct fc_frame_header *fh;
  863. unsigned int hlen; /* header length implies the version */
  864. unsigned int tlen; /* trailer length */
  865. unsigned int elen; /* eth header, may include vlan */
  866. struct fcoe_softc *fc;
  867. u8 sof, eof;
  868. struct fcoe_hdr *hp;
  869. WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
  870. fc = lport_priv(lp);
  871. fh = fc_frame_header_get(fp);
  872. skb = fp_skb(fp);
  873. wlen = skb->len / FCOE_WORD_TO_BYTE;
  874. if (!lp->link_up) {
  875. kfree_skb(skb);
  876. return 0;
  877. }
  878. if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
  879. fcoe_ctlr_els_send(&fc->ctlr, skb))
  880. return 0;
  881. sof = fr_sof(fp);
  882. eof = fr_eof(fp);
  883. elen = (fc->real_dev->priv_flags & IFF_802_1Q_VLAN) ?
  884. sizeof(struct vlan_ethhdr) : sizeof(struct ethhdr);
  885. hlen = sizeof(struct fcoe_hdr);
  886. tlen = sizeof(struct fcoe_crc_eof);
  887. wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
  888. /* crc offload */
  889. if (likely(lp->crc_offload)) {
  890. skb->ip_summed = CHECKSUM_PARTIAL;
  891. skb->csum_start = skb_headroom(skb);
  892. skb->csum_offset = skb->len;
  893. crc = 0;
  894. } else {
  895. skb->ip_summed = CHECKSUM_NONE;
  896. crc = fcoe_fc_crc(fp);
  897. }
  898. /* copy fc crc and eof to the skb buff */
  899. if (skb_is_nonlinear(skb)) {
  900. skb_frag_t *frag;
  901. if (fcoe_get_paged_crc_eof(skb, tlen)) {
  902. kfree_skb(skb);
  903. return -ENOMEM;
  904. }
  905. frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
  906. cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
  907. + frag->page_offset;
  908. } else {
  909. cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
  910. }
  911. memset(cp, 0, sizeof(*cp));
  912. cp->fcoe_eof = eof;
  913. cp->fcoe_crc32 = cpu_to_le32(~crc);
  914. if (skb_is_nonlinear(skb)) {
  915. kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
  916. cp = NULL;
  917. }
  918. /* adjust skb network/transport offsets to match mac/fcoe/fc */
  919. skb_push(skb, elen + hlen);
  920. skb_reset_mac_header(skb);
  921. skb_reset_network_header(skb);
  922. skb->mac_len = elen;
  923. skb->protocol = htons(ETH_P_FCOE);
  924. skb->dev = fc->real_dev;
  925. /* fill up mac and fcoe headers */
  926. eh = eth_hdr(skb);
  927. eh->h_proto = htons(ETH_P_FCOE);
  928. if (fc->ctlr.map_dest)
  929. fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
  930. else
  931. /* insert GW address */
  932. memcpy(eh->h_dest, fc->ctlr.dest_addr, ETH_ALEN);
  933. if (unlikely(fc->ctlr.flogi_oxid != FC_XID_UNKNOWN))
  934. memcpy(eh->h_source, fc->ctlr.ctl_src_addr, ETH_ALEN);
  935. else
  936. memcpy(eh->h_source, fc->ctlr.data_src_addr, ETH_ALEN);
  937. hp = (struct fcoe_hdr *)(eh + 1);
  938. memset(hp, 0, sizeof(*hp));
  939. if (FC_FCOE_VER)
  940. FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
  941. hp->fcoe_sof = sof;
  942. #ifdef NETIF_F_FSO
  943. /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
  944. if (lp->seq_offload && fr_max_payload(fp)) {
  945. skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
  946. skb_shinfo(skb)->gso_size = fr_max_payload(fp);
  947. } else {
  948. skb_shinfo(skb)->gso_type = 0;
  949. skb_shinfo(skb)->gso_size = 0;
  950. }
  951. #endif
  952. /* update tx stats: regardless if LLD fails */
  953. stats = fc_lport_get_stats(lp);
  954. stats->TxFrames++;
  955. stats->TxWords += wlen;
  956. /* send down to lld */
  957. fr_dev(fp) = lp;
  958. if (fc->fcoe_pending_queue.qlen)
  959. rc = fcoe_check_wait_queue(lp);
  960. if (rc == 0)
  961. rc = fcoe_start_io(skb);
  962. if (rc) {
  963. spin_lock_bh(&fc->fcoe_pending_queue.lock);
  964. __skb_queue_tail(&fc->fcoe_pending_queue, skb);
  965. spin_unlock_bh(&fc->fcoe_pending_queue.lock);
  966. if (fc->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
  967. lp->qfull = 1;
  968. }
  969. return 0;
  970. }
  971. /**
  972. * fcoe_percpu_receive_thread() - recv thread per cpu
  973. * @arg: ptr to the fcoe per cpu struct
  974. *
  975. * Return: 0 for success
  976. */
  977. int fcoe_percpu_receive_thread(void *arg)
  978. {
  979. struct fcoe_percpu_s *p = arg;
  980. u32 fr_len;
  981. struct fc_lport *lp;
  982. struct fcoe_rcv_info *fr;
  983. struct fcoe_dev_stats *stats;
  984. struct fc_frame_header *fh;
  985. struct sk_buff *skb;
  986. struct fcoe_crc_eof crc_eof;
  987. struct fc_frame *fp;
  988. u8 *mac = NULL;
  989. struct fcoe_softc *fc;
  990. struct fcoe_hdr *hp;
  991. set_user_nice(current, -20);
  992. while (!kthread_should_stop()) {
  993. spin_lock_bh(&p->fcoe_rx_list.lock);
  994. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) {
  995. set_current_state(TASK_INTERRUPTIBLE);
  996. spin_unlock_bh(&p->fcoe_rx_list.lock);
  997. schedule();
  998. set_current_state(TASK_RUNNING);
  999. if (kthread_should_stop())
  1000. return 0;
  1001. spin_lock_bh(&p->fcoe_rx_list.lock);
  1002. }
  1003. spin_unlock_bh(&p->fcoe_rx_list.lock);
  1004. fr = fcoe_dev_from_skb(skb);
  1005. lp = fr->fr_dev;
  1006. if (unlikely(lp == NULL)) {
  1007. FC_DBG("invalid HBA Structure");
  1008. kfree_skb(skb);
  1009. continue;
  1010. }
  1011. if (unlikely(debug_fcoe)) {
  1012. FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p "
  1013. "tail:%p end:%p sum:%d dev:%s",
  1014. skb->len, skb->data_len,
  1015. skb->head, skb->data, skb_tail_pointer(skb),
  1016. skb_end_pointer(skb), skb->csum,
  1017. skb->dev ? skb->dev->name : "<NULL>");
  1018. }
  1019. /*
  1020. * Save source MAC address before discarding header.
  1021. */
  1022. fc = lport_priv(lp);
  1023. if (skb_is_nonlinear(skb))
  1024. skb_linearize(skb); /* not ideal */
  1025. mac = eth_hdr(skb)->h_source;
  1026. /*
  1027. * Frame length checks and setting up the header pointers
  1028. * was done in fcoe_rcv already.
  1029. */
  1030. hp = (struct fcoe_hdr *) skb_network_header(skb);
  1031. fh = (struct fc_frame_header *) skb_transport_header(skb);
  1032. stats = fc_lport_get_stats(lp);
  1033. if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
  1034. if (stats->ErrorFrames < 5)
  1035. printk(KERN_WARNING "FCoE version "
  1036. "mismatch: The frame has "
  1037. "version %x, but the "
  1038. "initiator supports version "
  1039. "%x\n", FC_FCOE_DECAPS_VER(hp),
  1040. FC_FCOE_VER);
  1041. stats->ErrorFrames++;
  1042. kfree_skb(skb);
  1043. continue;
  1044. }
  1045. skb_pull(skb, sizeof(struct fcoe_hdr));
  1046. fr_len = skb->len - sizeof(struct fcoe_crc_eof);
  1047. stats->RxFrames++;
  1048. stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
  1049. fp = (struct fc_frame *)skb;
  1050. fc_frame_init(fp);
  1051. fr_dev(fp) = lp;
  1052. fr_sof(fp) = hp->fcoe_sof;
  1053. /* Copy out the CRC and EOF trailer for access */
  1054. if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
  1055. kfree_skb(skb);
  1056. continue;
  1057. }
  1058. fr_eof(fp) = crc_eof.fcoe_eof;
  1059. fr_crc(fp) = crc_eof.fcoe_crc32;
  1060. if (pskb_trim(skb, fr_len)) {
  1061. kfree_skb(skb);
  1062. continue;
  1063. }
  1064. /*
  1065. * We only check CRC if no offload is available and if it is
  1066. * it's solicited data, in which case, the FCP layer would
  1067. * check it during the copy.
  1068. */
  1069. if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
  1070. fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
  1071. else
  1072. fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
  1073. fh = fc_frame_header_get(fp);
  1074. if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
  1075. fh->fh_type == FC_TYPE_FCP) {
  1076. fc_exch_recv(lp, lp->emp, fp);
  1077. continue;
  1078. }
  1079. if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
  1080. if (le32_to_cpu(fr_crc(fp)) !=
  1081. ~crc32(~0, skb->data, fr_len)) {
  1082. if (debug_fcoe || stats->InvalidCRCCount < 5)
  1083. printk(KERN_WARNING "fcoe: dropping "
  1084. "frame with CRC error\n");
  1085. stats->InvalidCRCCount++;
  1086. stats->ErrorFrames++;
  1087. fc_frame_free(fp);
  1088. continue;
  1089. }
  1090. fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
  1091. }
  1092. if (unlikely(fc->ctlr.flogi_oxid != FC_XID_UNKNOWN) &&
  1093. fcoe_ctlr_recv_flogi(&fc->ctlr, fp, mac)) {
  1094. fc_frame_free(fp);
  1095. continue;
  1096. }
  1097. fc_exch_recv(lp, lp->emp, fp);
  1098. }
  1099. return 0;
  1100. }
  1101. /**
  1102. * fcoe_watchdog() - fcoe timer callback
  1103. * @vp:
  1104. *
  1105. * This checks the pending queue length for fcoe and set lport qfull
  1106. * if the FCOE_MAX_QUEUE_DEPTH is reached. This is done for all fc_lport on the
  1107. * fcoe_hostlist.
  1108. *
  1109. * Returns: 0 for success
  1110. */
  1111. void fcoe_watchdog(ulong vp)
  1112. {
  1113. struct fcoe_softc *fc;
  1114. read_lock(&fcoe_hostlist_lock);
  1115. list_for_each_entry(fc, &fcoe_hostlist, list) {
  1116. if (fc->ctlr.lp)
  1117. fcoe_check_wait_queue(fc->ctlr.lp);
  1118. }
  1119. read_unlock(&fcoe_hostlist_lock);
  1120. fcoe_timer.expires = jiffies + (1 * HZ);
  1121. add_timer(&fcoe_timer);
  1122. }
  1123. /**
  1124. * fcoe_check_wait_queue() - attempt to clear the transmit backlog
  1125. * @lp: the fc_lport
  1126. *
  1127. * This empties the wait_queue, dequeue the head of the wait_queue queue
  1128. * and calls fcoe_start_io() for each packet, if all skb have been
  1129. * transmitted, return qlen or -1 if a error occurs, then restore
  1130. * wait_queue and try again later.
  1131. *
  1132. * The wait_queue is used when the skb transmit fails. skb will go
  1133. * in the wait_queue which will be emptied by the timer function or
  1134. * by the next skb transmit.
  1135. *
  1136. * Returns: 0 for success
  1137. */
  1138. static int fcoe_check_wait_queue(struct fc_lport *lp)
  1139. {
  1140. struct fcoe_softc *fc = lport_priv(lp);
  1141. struct sk_buff *skb;
  1142. int rc = -1;
  1143. spin_lock_bh(&fc->fcoe_pending_queue.lock);
  1144. if (fc->fcoe_pending_queue_active)
  1145. goto out;
  1146. fc->fcoe_pending_queue_active = 1;
  1147. while (fc->fcoe_pending_queue.qlen) {
  1148. /* keep qlen > 0 until fcoe_start_io succeeds */
  1149. fc->fcoe_pending_queue.qlen++;
  1150. skb = __skb_dequeue(&fc->fcoe_pending_queue);
  1151. spin_unlock_bh(&fc->fcoe_pending_queue.lock);
  1152. rc = fcoe_start_io(skb);
  1153. spin_lock_bh(&fc->fcoe_pending_queue.lock);
  1154. if (rc) {
  1155. __skb_queue_head(&fc->fcoe_pending_queue, skb);
  1156. /* undo temporary increment above */
  1157. fc->fcoe_pending_queue.qlen--;
  1158. break;
  1159. }
  1160. /* undo temporary increment above */
  1161. fc->fcoe_pending_queue.qlen--;
  1162. }
  1163. if (fc->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
  1164. lp->qfull = 0;
  1165. fc->fcoe_pending_queue_active = 0;
  1166. rc = fc->fcoe_pending_queue.qlen;
  1167. out:
  1168. spin_unlock_bh(&fc->fcoe_pending_queue.lock);
  1169. return rc;
  1170. }
  1171. /**
  1172. * fcoe_dev_setup() - setup link change notification interface
  1173. */
  1174. static void fcoe_dev_setup(void)
  1175. {
  1176. register_netdevice_notifier(&fcoe_notifier);
  1177. }
  1178. /**
  1179. * fcoe_dev_cleanup() - cleanup link change notification interface
  1180. */
  1181. static void fcoe_dev_cleanup(void)
  1182. {
  1183. unregister_netdevice_notifier(&fcoe_notifier);
  1184. }
  1185. /**
  1186. * fcoe_device_notification() - netdev event notification callback
  1187. * @notifier: context of the notification
  1188. * @event: type of event
  1189. * @ptr: fixed array for output parsed ifname
  1190. *
  1191. * This function is called by the ethernet driver in case of link change event
  1192. *
  1193. * Returns: 0 for success
  1194. */
  1195. static int fcoe_device_notification(struct notifier_block *notifier,
  1196. ulong event, void *ptr)
  1197. {
  1198. struct fc_lport *lp = NULL;
  1199. struct net_device *real_dev = ptr;
  1200. struct fcoe_softc *fc;
  1201. struct fcoe_dev_stats *stats;
  1202. u32 link_possible = 1;
  1203. u32 mfs;
  1204. int rc = NOTIFY_OK;
  1205. read_lock(&fcoe_hostlist_lock);
  1206. list_for_each_entry(fc, &fcoe_hostlist, list) {
  1207. if (fc->real_dev == real_dev) {
  1208. lp = fc->ctlr.lp;
  1209. break;
  1210. }
  1211. }
  1212. read_unlock(&fcoe_hostlist_lock);
  1213. if (lp == NULL) {
  1214. rc = NOTIFY_DONE;
  1215. goto out;
  1216. }
  1217. switch (event) {
  1218. case NETDEV_DOWN:
  1219. case NETDEV_GOING_DOWN:
  1220. link_possible = 0;
  1221. break;
  1222. case NETDEV_UP:
  1223. case NETDEV_CHANGE:
  1224. break;
  1225. case NETDEV_CHANGEMTU:
  1226. mfs = fc->real_dev->mtu -
  1227. (sizeof(struct fcoe_hdr) +
  1228. sizeof(struct fcoe_crc_eof));
  1229. if (mfs >= FC_MIN_MAX_FRAME)
  1230. fc_set_mfs(lp, mfs);
  1231. break;
  1232. case NETDEV_REGISTER:
  1233. break;
  1234. default:
  1235. FC_DBG("Unknown event %ld from netdev netlink\n", event);
  1236. }
  1237. if (link_possible && !fcoe_link_ok(lp))
  1238. fcoe_ctlr_link_up(&fc->ctlr);
  1239. else if (fcoe_ctlr_link_down(&fc->ctlr)) {
  1240. stats = fc_lport_get_stats(lp);
  1241. stats->LinkFailureCount++;
  1242. fcoe_clean_pending_queue(lp);
  1243. }
  1244. out:
  1245. return rc;
  1246. }
  1247. /**
  1248. * fcoe_if_to_netdev() - parse a name buffer to get netdev
  1249. * @buffer: incoming buffer to be copied
  1250. *
  1251. * Returns: NULL or ptr to net_device
  1252. */
  1253. static struct net_device *fcoe_if_to_netdev(const char *buffer)
  1254. {
  1255. char *cp;
  1256. char ifname[IFNAMSIZ + 2];
  1257. if (buffer) {
  1258. strlcpy(ifname, buffer, IFNAMSIZ);
  1259. cp = ifname + strlen(ifname);
  1260. while (--cp >= ifname && *cp == '\n')
  1261. *cp = '\0';
  1262. return dev_get_by_name(&init_net, ifname);
  1263. }
  1264. return NULL;
  1265. }
  1266. /**
  1267. * fcoe_netdev_to_module_owner() - finds out the driver module of the netdev
  1268. * @netdev: the target netdev
  1269. *
  1270. * Returns: ptr to the struct module, NULL for failure
  1271. */
  1272. static struct module *
  1273. fcoe_netdev_to_module_owner(const struct net_device *netdev)
  1274. {
  1275. struct device *dev;
  1276. if (!netdev)
  1277. return NULL;
  1278. dev = netdev->dev.parent;
  1279. if (!dev)
  1280. return NULL;
  1281. if (!dev->driver)
  1282. return NULL;
  1283. return dev->driver->owner;
  1284. }
  1285. /**
  1286. * fcoe_ethdrv_get() - Hold the Ethernet driver
  1287. * @netdev: the target netdev
  1288. *
  1289. * Holds the Ethernet driver module by try_module_get() for
  1290. * the corresponding netdev.
  1291. *
  1292. * Returns: 0 for success
  1293. */
  1294. static int fcoe_ethdrv_get(const struct net_device *netdev)
  1295. {
  1296. struct module *owner;
  1297. owner = fcoe_netdev_to_module_owner(netdev);
  1298. if (owner) {
  1299. printk(KERN_DEBUG "fcoe:hold driver module %s for %s\n",
  1300. module_name(owner), netdev->name);
  1301. return try_module_get(owner);
  1302. }
  1303. return -ENODEV;
  1304. }
  1305. /**
  1306. * fcoe_ethdrv_put() - Release the Ethernet driver
  1307. * @netdev: the target netdev
  1308. *
  1309. * Releases the Ethernet driver module by module_put for
  1310. * the corresponding netdev.
  1311. *
  1312. * Returns: 0 for success
  1313. */
  1314. static int fcoe_ethdrv_put(const struct net_device *netdev)
  1315. {
  1316. struct module *owner;
  1317. owner = fcoe_netdev_to_module_owner(netdev);
  1318. if (owner) {
  1319. printk(KERN_DEBUG "fcoe:release driver module %s for %s\n",
  1320. module_name(owner), netdev->name);
  1321. module_put(owner);
  1322. return 0;
  1323. }
  1324. return -ENODEV;
  1325. }
  1326. /**
  1327. * fcoe_destroy() - handles the destroy from sysfs
  1328. * @buffer: expected to be an eth if name
  1329. * @kp: associated kernel param
  1330. *
  1331. * Returns: 0 for success
  1332. */
  1333. static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
  1334. {
  1335. int rc;
  1336. struct net_device *netdev;
  1337. netdev = fcoe_if_to_netdev(buffer);
  1338. if (!netdev) {
  1339. rc = -ENODEV;
  1340. goto out_nodev;
  1341. }
  1342. /* look for existing lport */
  1343. if (!fcoe_hostlist_lookup(netdev)) {
  1344. rc = -ENODEV;
  1345. goto out_putdev;
  1346. }
  1347. rc = fcoe_if_destroy(netdev);
  1348. if (rc) {
  1349. printk(KERN_ERR "fcoe: fcoe_if_destroy(%s) failed\n",
  1350. netdev->name);
  1351. rc = -EIO;
  1352. goto out_putdev;
  1353. }
  1354. fcoe_ethdrv_put(netdev);
  1355. rc = 0;
  1356. out_putdev:
  1357. dev_put(netdev);
  1358. out_nodev:
  1359. return rc;
  1360. }
  1361. /**
  1362. * fcoe_create() - Handles the create call from sysfs
  1363. * @buffer: expected to be an eth if name
  1364. * @kp: associated kernel param
  1365. *
  1366. * Returns: 0 for success
  1367. */
  1368. static int fcoe_create(const char *buffer, struct kernel_param *kp)
  1369. {
  1370. int rc;
  1371. struct net_device *netdev;
  1372. netdev = fcoe_if_to_netdev(buffer);
  1373. if (!netdev) {
  1374. rc = -ENODEV;
  1375. goto out_nodev;
  1376. }
  1377. /* look for existing lport */
  1378. if (fcoe_hostlist_lookup(netdev)) {
  1379. rc = -EEXIST;
  1380. goto out_putdev;
  1381. }
  1382. fcoe_ethdrv_get(netdev);
  1383. rc = fcoe_if_create(netdev);
  1384. if (rc) {
  1385. printk(KERN_ERR "fcoe: fcoe_if_create(%s) failed\n",
  1386. netdev->name);
  1387. fcoe_ethdrv_put(netdev);
  1388. rc = -EIO;
  1389. goto out_putdev;
  1390. }
  1391. rc = 0;
  1392. out_putdev:
  1393. dev_put(netdev);
  1394. out_nodev:
  1395. return rc;
  1396. }
  1397. module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR);
  1398. __MODULE_PARM_TYPE(create, "string");
  1399. MODULE_PARM_DESC(create, "Create fcoe port using net device passed in.");
  1400. module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR);
  1401. __MODULE_PARM_TYPE(destroy, "string");
  1402. MODULE_PARM_DESC(destroy, "Destroy fcoe port");
  1403. /**
  1404. * fcoe_link_ok() - Check if link is ok for the fc_lport
  1405. * @lp: ptr to the fc_lport
  1406. *
  1407. * Any permanently-disqualifying conditions have been previously checked.
  1408. * This also updates the speed setting, which may change with link for 100/1000.
  1409. *
  1410. * This function should probably be checking for PAUSE support at some point
  1411. * in the future. Currently Per-priority-pause is not determinable using
  1412. * ethtool, so we shouldn't be restrictive until that problem is resolved.
  1413. *
  1414. * Returns: 0 if link is OK for use by FCoE.
  1415. *
  1416. */
  1417. int fcoe_link_ok(struct fc_lport *lp)
  1418. {
  1419. struct fcoe_softc *fc = lport_priv(lp);
  1420. struct net_device *dev = fc->real_dev;
  1421. struct ethtool_cmd ecmd = { ETHTOOL_GSET };
  1422. int rc = 0;
  1423. if ((dev->flags & IFF_UP) && netif_carrier_ok(dev)) {
  1424. dev = fc->phys_dev;
  1425. if (dev->ethtool_ops->get_settings) {
  1426. dev->ethtool_ops->get_settings(dev, &ecmd);
  1427. lp->link_supported_speeds &=
  1428. ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
  1429. if (ecmd.supported & (SUPPORTED_1000baseT_Half |
  1430. SUPPORTED_1000baseT_Full))
  1431. lp->link_supported_speeds |= FC_PORTSPEED_1GBIT;
  1432. if (ecmd.supported & SUPPORTED_10000baseT_Full)
  1433. lp->link_supported_speeds |=
  1434. FC_PORTSPEED_10GBIT;
  1435. if (ecmd.speed == SPEED_1000)
  1436. lp->link_speed = FC_PORTSPEED_1GBIT;
  1437. if (ecmd.speed == SPEED_10000)
  1438. lp->link_speed = FC_PORTSPEED_10GBIT;
  1439. }
  1440. } else
  1441. rc = -1;
  1442. return rc;
  1443. }
  1444. /**
  1445. * fcoe_percpu_clean() - Clear the pending skbs for an lport
  1446. * @lp: the fc_lport
  1447. */
  1448. void fcoe_percpu_clean(struct fc_lport *lp)
  1449. {
  1450. struct fcoe_percpu_s *pp;
  1451. struct fcoe_rcv_info *fr;
  1452. struct sk_buff_head *list;
  1453. struct sk_buff *skb, *next;
  1454. struct sk_buff *head;
  1455. unsigned int cpu;
  1456. for_each_possible_cpu(cpu) {
  1457. pp = &per_cpu(fcoe_percpu, cpu);
  1458. spin_lock_bh(&pp->fcoe_rx_list.lock);
  1459. list = &pp->fcoe_rx_list;
  1460. head = list->next;
  1461. for (skb = head; skb != (struct sk_buff *)list;
  1462. skb = next) {
  1463. next = skb->next;
  1464. fr = fcoe_dev_from_skb(skb);
  1465. if (fr->fr_dev == lp) {
  1466. __skb_unlink(skb, list);
  1467. kfree_skb(skb);
  1468. }
  1469. }
  1470. spin_unlock_bh(&pp->fcoe_rx_list.lock);
  1471. }
  1472. }
  1473. /**
  1474. * fcoe_clean_pending_queue() - Dequeue a skb and free it
  1475. * @lp: the corresponding fc_lport
  1476. *
  1477. * Returns: none
  1478. */
  1479. void fcoe_clean_pending_queue(struct fc_lport *lp)
  1480. {
  1481. struct fcoe_softc *fc = lport_priv(lp);
  1482. struct sk_buff *skb;
  1483. spin_lock_bh(&fc->fcoe_pending_queue.lock);
  1484. while ((skb = __skb_dequeue(&fc->fcoe_pending_queue)) != NULL) {
  1485. spin_unlock_bh(&fc->fcoe_pending_queue.lock);
  1486. kfree_skb(skb);
  1487. spin_lock_bh(&fc->fcoe_pending_queue.lock);
  1488. }
  1489. spin_unlock_bh(&fc->fcoe_pending_queue.lock);
  1490. }
  1491. /**
  1492. * fcoe_reset() - Resets the fcoe
  1493. * @shost: shost the reset is from
  1494. *
  1495. * Returns: always 0
  1496. */
  1497. int fcoe_reset(struct Scsi_Host *shost)
  1498. {
  1499. struct fc_lport *lport = shost_priv(shost);
  1500. fc_lport_reset(lport);
  1501. return 0;
  1502. }
  1503. /**
  1504. * fcoe_hostlist_lookup_softc() - find the corresponding lport by a given device
  1505. * @dev: this is currently ptr to net_device
  1506. *
  1507. * Returns: NULL or the located fcoe_softc
  1508. */
  1509. static struct fcoe_softc *
  1510. fcoe_hostlist_lookup_softc(const struct net_device *dev)
  1511. {
  1512. struct fcoe_softc *fc;
  1513. read_lock(&fcoe_hostlist_lock);
  1514. list_for_each_entry(fc, &fcoe_hostlist, list) {
  1515. if (fc->real_dev == dev) {
  1516. read_unlock(&fcoe_hostlist_lock);
  1517. return fc;
  1518. }
  1519. }
  1520. read_unlock(&fcoe_hostlist_lock);
  1521. return NULL;
  1522. }
  1523. /**
  1524. * fcoe_hostlist_lookup() - Find the corresponding lport by netdev
  1525. * @netdev: ptr to net_device
  1526. *
  1527. * Returns: 0 for success
  1528. */
  1529. struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
  1530. {
  1531. struct fcoe_softc *fc;
  1532. fc = fcoe_hostlist_lookup_softc(netdev);
  1533. return (fc) ? fc->ctlr.lp : NULL;
  1534. }
  1535. /**
  1536. * fcoe_hostlist_add() - Add a lport to lports list
  1537. * @lp: ptr to the fc_lport to be added
  1538. *
  1539. * Returns: 0 for success
  1540. */
  1541. int fcoe_hostlist_add(const struct fc_lport *lp)
  1542. {
  1543. struct fcoe_softc *fc;
  1544. fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
  1545. if (!fc) {
  1546. fc = lport_priv(lp);
  1547. write_lock_bh(&fcoe_hostlist_lock);
  1548. list_add_tail(&fc->list, &fcoe_hostlist);
  1549. write_unlock_bh(&fcoe_hostlist_lock);
  1550. }
  1551. return 0;
  1552. }
  1553. /**
  1554. * fcoe_hostlist_remove() - remove a lport from lports list
  1555. * @lp: ptr to the fc_lport to be removed
  1556. *
  1557. * Returns: 0 for success
  1558. */
  1559. int fcoe_hostlist_remove(const struct fc_lport *lp)
  1560. {
  1561. struct fcoe_softc *fc;
  1562. fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
  1563. BUG_ON(!fc);
  1564. write_lock_bh(&fcoe_hostlist_lock);
  1565. list_del(&fc->list);
  1566. write_unlock_bh(&fcoe_hostlist_lock);
  1567. return 0;
  1568. }
  1569. /**
  1570. * fcoe_init() - fcoe module loading initialization
  1571. *
  1572. * Returns 0 on success, negative on failure
  1573. */
  1574. static int __init fcoe_init(void)
  1575. {
  1576. unsigned int cpu;
  1577. int rc = 0;
  1578. struct fcoe_percpu_s *p;
  1579. INIT_LIST_HEAD(&fcoe_hostlist);
  1580. rwlock_init(&fcoe_hostlist_lock);
  1581. for_each_possible_cpu(cpu) {
  1582. p = &per_cpu(fcoe_percpu, cpu);
  1583. skb_queue_head_init(&p->fcoe_rx_list);
  1584. }
  1585. for_each_online_cpu(cpu)
  1586. fcoe_percpu_thread_create(cpu);
  1587. /* Initialize per CPU interrupt thread */
  1588. rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
  1589. if (rc)
  1590. goto out_free;
  1591. /* Setup link change notification */
  1592. fcoe_dev_setup();
  1593. setup_timer(&fcoe_timer, fcoe_watchdog, 0);
  1594. mod_timer(&fcoe_timer, jiffies + (10 * HZ));
  1595. fcoe_if_init();
  1596. return 0;
  1597. out_free:
  1598. for_each_online_cpu(cpu) {
  1599. fcoe_percpu_thread_destroy(cpu);
  1600. }
  1601. return rc;
  1602. }
  1603. module_init(fcoe_init);
  1604. /**
  1605. * fcoe_exit() - fcoe module unloading cleanup
  1606. *
  1607. * Returns 0 on success, negative on failure
  1608. */
  1609. static void __exit fcoe_exit(void)
  1610. {
  1611. unsigned int cpu;
  1612. struct fcoe_softc *fc, *tmp;
  1613. fcoe_dev_cleanup();
  1614. /* Stop the timer */
  1615. del_timer_sync(&fcoe_timer);
  1616. /* releases the associated fcoe hosts */
  1617. list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list)
  1618. fcoe_if_destroy(fc->real_dev);
  1619. unregister_hotcpu_notifier(&fcoe_cpu_notifier);
  1620. for_each_online_cpu(cpu) {
  1621. fcoe_percpu_thread_destroy(cpu);
  1622. }
  1623. /* detach from scsi transport */
  1624. fcoe_if_exit();
  1625. }
  1626. module_exit(fcoe_exit);