fcoe.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878
  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 Prototyes */
  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. * @shost: ptr to the parent scsi host
  123. *
  124. * Returns: 0 for success
  125. */
  126. static int fcoe_lport_config(struct fc_lport *lp)
  127. {
  128. lp->link_up = 0;
  129. lp->qfull = 0;
  130. lp->max_retry_count = 3;
  131. lp->e_d_tov = 2 * 1000; /* FC-FS default */
  132. lp->r_a_tov = 2 * 2 * 1000;
  133. lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
  134. FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
  135. fc_lport_init_stats(lp);
  136. /* lport fc_lport related configuration */
  137. fc_lport_config(lp);
  138. /* offload related configuration */
  139. lp->crc_offload = 0;
  140. lp->seq_offload = 0;
  141. lp->lro_enabled = 0;
  142. lp->lro_xid = 0;
  143. lp->lso_max = 0;
  144. return 0;
  145. }
  146. /**
  147. * fcoe_netdev_config() - Set up netdev for SW FCoE
  148. * @lp : ptr to the fc_lport
  149. * @netdev : ptr to the associated netdevice struct
  150. *
  151. * Must be called after fcoe_lport_config() as it will use lport mutex
  152. *
  153. * Returns : 0 for success
  154. */
  155. static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
  156. {
  157. u32 mfs;
  158. u64 wwnn, wwpn;
  159. struct fcoe_softc *fc;
  160. u8 flogi_maddr[ETH_ALEN];
  161. /* Setup lport private data to point to fcoe softc */
  162. fc = lport_priv(lp);
  163. fc->ctlr.lp = lp;
  164. fc->real_dev = netdev;
  165. fc->phys_dev = netdev;
  166. /* Require support for get_pauseparam ethtool op. */
  167. if (netdev->priv_flags & IFF_802_1Q_VLAN)
  168. fc->phys_dev = vlan_dev_real_dev(netdev);
  169. /* Do not support for bonding device */
  170. if ((fc->real_dev->priv_flags & IFF_MASTER_ALB) ||
  171. (fc->real_dev->priv_flags & IFF_SLAVE_INACTIVE) ||
  172. (fc->real_dev->priv_flags & IFF_MASTER_8023AD)) {
  173. return -EOPNOTSUPP;
  174. }
  175. /*
  176. * Determine max frame size based on underlying device and optional
  177. * user-configured limit. If the MFS is too low, fcoe_link_ok()
  178. * will return 0, so do this first.
  179. */
  180. mfs = fc->real_dev->mtu - (sizeof(struct fcoe_hdr) +
  181. sizeof(struct fcoe_crc_eof));
  182. if (fc_set_mfs(lp, mfs))
  183. return -EINVAL;
  184. /* offload features support */
  185. if (fc->real_dev->features & NETIF_F_SG)
  186. lp->sg_supp = 1;
  187. #ifdef NETIF_F_FCOE_CRC
  188. if (netdev->features & NETIF_F_FCOE_CRC) {
  189. lp->crc_offload = 1;
  190. printk(KERN_DEBUG "fcoe:%s supports FCCRC offload\n",
  191. netdev->name);
  192. }
  193. #endif
  194. #ifdef NETIF_F_FSO
  195. if (netdev->features & NETIF_F_FSO) {
  196. lp->seq_offload = 1;
  197. lp->lso_max = netdev->gso_max_size;
  198. printk(KERN_DEBUG "fcoe:%s supports LSO for max len 0x%x\n",
  199. netdev->name, lp->lso_max);
  200. }
  201. #endif
  202. if (netdev->fcoe_ddp_xid) {
  203. lp->lro_enabled = 1;
  204. lp->lro_xid = netdev->fcoe_ddp_xid;
  205. printk(KERN_DEBUG "fcoe:%s supports LRO for max xid 0x%x\n",
  206. netdev->name, lp->lro_xid);
  207. }
  208. skb_queue_head_init(&fc->fcoe_pending_queue);
  209. fc->fcoe_pending_queue_active = 0;
  210. /* setup Source Mac Address */
  211. memcpy(fc->ctlr.ctl_src_addr, fc->real_dev->dev_addr,
  212. fc->real_dev->addr_len);
  213. wwnn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 1, 0);
  214. fc_set_wwnn(lp, wwnn);
  215. /* XXX - 3rd arg needs to be vlan id */
  216. wwpn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 2, 0);
  217. fc_set_wwpn(lp, wwpn);
  218. /*
  219. * Add FCoE MAC address as second unicast MAC address
  220. * or enter promiscuous mode if not capable of listening
  221. * for multiple unicast MACs.
  222. */
  223. rtnl_lock();
  224. memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
  225. dev_unicast_add(fc->real_dev, flogi_maddr, ETH_ALEN);
  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 revieve 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 singluar 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. * @odldev: 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. EXPORT_SYMBOL_GPL(fcoe_rcv);
  763. /**
  764. * fcoe_start_io() - pass to netdev to start xmit for fcoe
  765. * @skb: the skb to be xmitted
  766. *
  767. * Returns: 0 for success
  768. */
  769. static inline int fcoe_start_io(struct sk_buff *skb)
  770. {
  771. int rc;
  772. skb_get(skb);
  773. rc = dev_queue_xmit(skb);
  774. if (rc != 0)
  775. return rc;
  776. kfree_skb(skb);
  777. return 0;
  778. }
  779. /**
  780. * fcoe_get_paged_crc_eof() - in case we need alloc a page for crc_eof
  781. * @skb: the skb to be xmitted
  782. * @tlen: total len
  783. *
  784. * Returns: 0 for success
  785. */
  786. static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
  787. {
  788. struct fcoe_percpu_s *fps;
  789. struct page *page;
  790. fps = &get_cpu_var(fcoe_percpu);
  791. page = fps->crc_eof_page;
  792. if (!page) {
  793. page = alloc_page(GFP_ATOMIC);
  794. if (!page) {
  795. put_cpu_var(fcoe_percpu);
  796. return -ENOMEM;
  797. }
  798. fps->crc_eof_page = page;
  799. fps->crc_eof_offset = 0;
  800. }
  801. get_page(page);
  802. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
  803. fps->crc_eof_offset, tlen);
  804. skb->len += tlen;
  805. skb->data_len += tlen;
  806. skb->truesize += tlen;
  807. fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
  808. if (fps->crc_eof_offset >= PAGE_SIZE) {
  809. fps->crc_eof_page = NULL;
  810. fps->crc_eof_offset = 0;
  811. put_page(page);
  812. }
  813. put_cpu_var(fcoe_percpu);
  814. return 0;
  815. }
  816. /**
  817. * fcoe_fc_crc() - calculates FC CRC in this fcoe skb
  818. * @fp: the fc_frame containg data to be checksummed
  819. *
  820. * This uses crc32() to calculate the crc for fc frame
  821. * Return : 32 bit crc
  822. */
  823. u32 fcoe_fc_crc(struct fc_frame *fp)
  824. {
  825. struct sk_buff *skb = fp_skb(fp);
  826. struct skb_frag_struct *frag;
  827. unsigned char *data;
  828. unsigned long off, len, clen;
  829. u32 crc;
  830. unsigned i;
  831. crc = crc32(~0, skb->data, skb_headlen(skb));
  832. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  833. frag = &skb_shinfo(skb)->frags[i];
  834. off = frag->page_offset;
  835. len = frag->size;
  836. while (len > 0) {
  837. clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
  838. data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
  839. KM_SKB_DATA_SOFTIRQ);
  840. crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
  841. kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
  842. off += clen;
  843. len -= clen;
  844. }
  845. }
  846. return crc;
  847. }
  848. /**
  849. * fcoe_xmit() - FCoE frame transmit function
  850. * @lp: the associated local port
  851. * @fp: the fc_frame to be transmitted
  852. *
  853. * Return : 0 for success
  854. */
  855. int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
  856. {
  857. int wlen, rc = 0;
  858. u32 crc;
  859. struct ethhdr *eh;
  860. struct fcoe_crc_eof *cp;
  861. struct sk_buff *skb;
  862. struct fcoe_dev_stats *stats;
  863. struct fc_frame_header *fh;
  864. unsigned int hlen; /* header length implies the version */
  865. unsigned int tlen; /* trailer length */
  866. unsigned int elen; /* eth header, may include vlan */
  867. struct fcoe_softc *fc;
  868. u8 sof, eof;
  869. struct fcoe_hdr *hp;
  870. WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
  871. fc = lport_priv(lp);
  872. fh = fc_frame_header_get(fp);
  873. skb = fp_skb(fp);
  874. wlen = skb->len / FCOE_WORD_TO_BYTE;
  875. if (!lp->link_up) {
  876. kfree(skb);
  877. return 0;
  878. }
  879. if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
  880. fcoe_ctlr_els_send(&fc->ctlr, skb))
  881. return 0;
  882. sof = fr_sof(fp);
  883. eof = fr_eof(fp);
  884. elen = (fc->real_dev->priv_flags & IFF_802_1Q_VLAN) ?
  885. sizeof(struct vlan_ethhdr) : sizeof(struct ethhdr);
  886. hlen = sizeof(struct fcoe_hdr);
  887. tlen = sizeof(struct fcoe_crc_eof);
  888. wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
  889. /* crc offload */
  890. if (likely(lp->crc_offload)) {
  891. skb->ip_summed = CHECKSUM_PARTIAL;
  892. skb->csum_start = skb_headroom(skb);
  893. skb->csum_offset = skb->len;
  894. crc = 0;
  895. } else {
  896. skb->ip_summed = CHECKSUM_NONE;
  897. crc = fcoe_fc_crc(fp);
  898. }
  899. /* copy fc crc and eof to the skb buff */
  900. if (skb_is_nonlinear(skb)) {
  901. skb_frag_t *frag;
  902. if (fcoe_get_paged_crc_eof(skb, tlen)) {
  903. kfree_skb(skb);
  904. return -ENOMEM;
  905. }
  906. frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
  907. cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
  908. + frag->page_offset;
  909. } else {
  910. cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
  911. }
  912. memset(cp, 0, sizeof(*cp));
  913. cp->fcoe_eof = eof;
  914. cp->fcoe_crc32 = cpu_to_le32(~crc);
  915. if (skb_is_nonlinear(skb)) {
  916. kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
  917. cp = NULL;
  918. }
  919. /* adjust skb netowrk/transport offsets to match mac/fcoe/fc */
  920. skb_push(skb, elen + hlen);
  921. skb_reset_mac_header(skb);
  922. skb_reset_network_header(skb);
  923. skb->mac_len = elen;
  924. skb->protocol = htons(ETH_P_FCOE);
  925. skb->dev = fc->real_dev;
  926. /* fill up mac and fcoe headers */
  927. eh = eth_hdr(skb);
  928. eh->h_proto = htons(ETH_P_FCOE);
  929. if (fc->ctlr.map_dest)
  930. fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
  931. else
  932. /* insert GW address */
  933. memcpy(eh->h_dest, fc->ctlr.dest_addr, ETH_ALEN);
  934. if (unlikely(fc->ctlr.flogi_oxid != FC_XID_UNKNOWN))
  935. memcpy(eh->h_source, fc->ctlr.ctl_src_addr, ETH_ALEN);
  936. else
  937. memcpy(eh->h_source, fc->ctlr.data_src_addr, ETH_ALEN);
  938. hp = (struct fcoe_hdr *)(eh + 1);
  939. memset(hp, 0, sizeof(*hp));
  940. if (FC_FCOE_VER)
  941. FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
  942. hp->fcoe_sof = sof;
  943. #ifdef NETIF_F_FSO
  944. /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
  945. if (lp->seq_offload && fr_max_payload(fp)) {
  946. skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
  947. skb_shinfo(skb)->gso_size = fr_max_payload(fp);
  948. } else {
  949. skb_shinfo(skb)->gso_type = 0;
  950. skb_shinfo(skb)->gso_size = 0;
  951. }
  952. #endif
  953. /* update tx stats: regardless if LLD fails */
  954. stats = fc_lport_get_stats(lp);
  955. stats->TxFrames++;
  956. stats->TxWords += wlen;
  957. /* send down to lld */
  958. fr_dev(fp) = lp;
  959. if (fc->fcoe_pending_queue.qlen)
  960. rc = fcoe_check_wait_queue(lp);
  961. if (rc == 0)
  962. rc = fcoe_start_io(skb);
  963. if (rc) {
  964. spin_lock_bh(&fc->fcoe_pending_queue.lock);
  965. __skb_queue_tail(&fc->fcoe_pending_queue, skb);
  966. spin_unlock_bh(&fc->fcoe_pending_queue.lock);
  967. if (fc->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
  968. lp->qfull = 1;
  969. }
  970. return 0;
  971. }
  972. EXPORT_SYMBOL_GPL(fcoe_xmit);
  973. /**
  974. * fcoe_percpu_receive_thread() - recv thread per cpu
  975. * @arg: ptr to the fcoe per cpu struct
  976. *
  977. * Return: 0 for success
  978. */
  979. int fcoe_percpu_receive_thread(void *arg)
  980. {
  981. struct fcoe_percpu_s *p = arg;
  982. u32 fr_len;
  983. struct fc_lport *lp;
  984. struct fcoe_rcv_info *fr;
  985. struct fcoe_dev_stats *stats;
  986. struct fc_frame_header *fh;
  987. struct sk_buff *skb;
  988. struct fcoe_crc_eof crc_eof;
  989. struct fc_frame *fp;
  990. u8 *mac = NULL;
  991. struct fcoe_softc *fc;
  992. struct fcoe_hdr *hp;
  993. set_user_nice(current, -20);
  994. while (!kthread_should_stop()) {
  995. spin_lock_bh(&p->fcoe_rx_list.lock);
  996. while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) {
  997. set_current_state(TASK_INTERRUPTIBLE);
  998. spin_unlock_bh(&p->fcoe_rx_list.lock);
  999. schedule();
  1000. set_current_state(TASK_RUNNING);
  1001. if (kthread_should_stop())
  1002. return 0;
  1003. spin_lock_bh(&p->fcoe_rx_list.lock);
  1004. }
  1005. spin_unlock_bh(&p->fcoe_rx_list.lock);
  1006. fr = fcoe_dev_from_skb(skb);
  1007. lp = fr->fr_dev;
  1008. if (unlikely(lp == NULL)) {
  1009. FC_DBG("invalid HBA Structure");
  1010. kfree_skb(skb);
  1011. continue;
  1012. }
  1013. if (unlikely(debug_fcoe)) {
  1014. FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p "
  1015. "tail:%p end:%p sum:%d dev:%s",
  1016. skb->len, skb->data_len,
  1017. skb->head, skb->data, skb_tail_pointer(skb),
  1018. skb_end_pointer(skb), skb->csum,
  1019. skb->dev ? skb->dev->name : "<NULL>");
  1020. }
  1021. /*
  1022. * Save source MAC address before discarding header.
  1023. */
  1024. fc = lport_priv(lp);
  1025. if (skb_is_nonlinear(skb))
  1026. skb_linearize(skb); /* not ideal */
  1027. mac = eth_hdr(skb)->h_source;
  1028. /*
  1029. * Frame length checks and setting up the header pointers
  1030. * was done in fcoe_rcv already.
  1031. */
  1032. hp = (struct fcoe_hdr *) skb_network_header(skb);
  1033. fh = (struct fc_frame_header *) skb_transport_header(skb);
  1034. stats = fc_lport_get_stats(lp);
  1035. if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
  1036. if (stats->ErrorFrames < 5)
  1037. printk(KERN_WARNING "FCoE version "
  1038. "mismatch: The frame has "
  1039. "version %x, but the "
  1040. "initiator supports version "
  1041. "%x\n", FC_FCOE_DECAPS_VER(hp),
  1042. FC_FCOE_VER);
  1043. stats->ErrorFrames++;
  1044. kfree_skb(skb);
  1045. continue;
  1046. }
  1047. skb_pull(skb, sizeof(struct fcoe_hdr));
  1048. fr_len = skb->len - sizeof(struct fcoe_crc_eof);
  1049. stats->RxFrames++;
  1050. stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
  1051. fp = (struct fc_frame *)skb;
  1052. fc_frame_init(fp);
  1053. fr_dev(fp) = lp;
  1054. fr_sof(fp) = hp->fcoe_sof;
  1055. /* Copy out the CRC and EOF trailer for access */
  1056. if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
  1057. kfree_skb(skb);
  1058. continue;
  1059. }
  1060. fr_eof(fp) = crc_eof.fcoe_eof;
  1061. fr_crc(fp) = crc_eof.fcoe_crc32;
  1062. if (pskb_trim(skb, fr_len)) {
  1063. kfree_skb(skb);
  1064. continue;
  1065. }
  1066. /*
  1067. * We only check CRC if no offload is available and if it is
  1068. * it's solicited data, in which case, the FCP layer would
  1069. * check it during the copy.
  1070. */
  1071. if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
  1072. fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
  1073. else
  1074. fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
  1075. fh = fc_frame_header_get(fp);
  1076. if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
  1077. fh->fh_type == FC_TYPE_FCP) {
  1078. fc_exch_recv(lp, lp->emp, fp);
  1079. continue;
  1080. }
  1081. if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
  1082. if (le32_to_cpu(fr_crc(fp)) !=
  1083. ~crc32(~0, skb->data, fr_len)) {
  1084. if (debug_fcoe || stats->InvalidCRCCount < 5)
  1085. printk(KERN_WARNING "fcoe: dropping "
  1086. "frame with CRC error\n");
  1087. stats->InvalidCRCCount++;
  1088. stats->ErrorFrames++;
  1089. fc_frame_free(fp);
  1090. continue;
  1091. }
  1092. fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
  1093. }
  1094. if (unlikely(fc->ctlr.flogi_oxid != FC_XID_UNKNOWN) &&
  1095. fcoe_ctlr_recv_flogi(&fc->ctlr, fp, mac)) {
  1096. fc_frame_free(fp);
  1097. continue;
  1098. }
  1099. fc_exch_recv(lp, lp->emp, fp);
  1100. }
  1101. return 0;
  1102. }
  1103. /**
  1104. * fcoe_watchdog() - fcoe timer callback
  1105. * @vp:
  1106. *
  1107. * This checks the pending queue length for fcoe and set lport qfull
  1108. * if the FCOE_MAX_QUEUE_DEPTH is reached. This is done for all fc_lport on the
  1109. * fcoe_hostlist.
  1110. *
  1111. * Returns: 0 for success
  1112. */
  1113. void fcoe_watchdog(ulong vp)
  1114. {
  1115. struct fcoe_softc *fc;
  1116. read_lock(&fcoe_hostlist_lock);
  1117. list_for_each_entry(fc, &fcoe_hostlist, list) {
  1118. if (fc->ctlr.lp)
  1119. fcoe_check_wait_queue(fc->ctlr.lp);
  1120. }
  1121. read_unlock(&fcoe_hostlist_lock);
  1122. fcoe_timer.expires = jiffies + (1 * HZ);
  1123. add_timer(&fcoe_timer);
  1124. }
  1125. /**
  1126. * fcoe_check_wait_queue() - put the skb into fcoe pending xmit queue
  1127. * @lp: the fc_port for this skb
  1128. * @skb: the associated skb to be xmitted
  1129. *
  1130. * This empties the wait_queue, dequeue the head of the wait_queue queue
  1131. * and calls fcoe_start_io() for each packet, if all skb have been
  1132. * transmitted, return qlen or -1 if a error occurs, then restore
  1133. * wait_queue and try again later.
  1134. *
  1135. * The wait_queue is used when the skb transmit fails. skb will go
  1136. * in the wait_queue which will be emptied by the time function OR
  1137. * by the next skb transmit.
  1138. *
  1139. * Returns: 0 for success
  1140. */
  1141. static int fcoe_check_wait_queue(struct fc_lport *lp)
  1142. {
  1143. struct fcoe_softc *fc = lport_priv(lp);
  1144. struct sk_buff *skb;
  1145. int rc = -1;
  1146. spin_lock_bh(&fc->fcoe_pending_queue.lock);
  1147. if (fc->fcoe_pending_queue_active)
  1148. goto out;
  1149. fc->fcoe_pending_queue_active = 1;
  1150. while (fc->fcoe_pending_queue.qlen) {
  1151. /* keep qlen > 0 until fcoe_start_io succeeds */
  1152. fc->fcoe_pending_queue.qlen++;
  1153. skb = __skb_dequeue(&fc->fcoe_pending_queue);
  1154. spin_unlock_bh(&fc->fcoe_pending_queue.lock);
  1155. rc = fcoe_start_io(skb);
  1156. spin_lock_bh(&fc->fcoe_pending_queue.lock);
  1157. if (rc) {
  1158. __skb_queue_head(&fc->fcoe_pending_queue, skb);
  1159. /* undo temporary increment above */
  1160. fc->fcoe_pending_queue.qlen--;
  1161. break;
  1162. }
  1163. /* undo temporary increment above */
  1164. fc->fcoe_pending_queue.qlen--;
  1165. }
  1166. if (fc->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
  1167. lp->qfull = 0;
  1168. fc->fcoe_pending_queue_active = 0;
  1169. rc = fc->fcoe_pending_queue.qlen;
  1170. out:
  1171. spin_unlock_bh(&fc->fcoe_pending_queue.lock);
  1172. return rc;
  1173. }
  1174. /**
  1175. * fcoe_dev_setup() - setup link change notification interface
  1176. */
  1177. static void fcoe_dev_setup()
  1178. {
  1179. /*
  1180. * here setup a interface specific wd time to
  1181. * monitor the link state
  1182. */
  1183. register_netdevice_notifier(&fcoe_notifier);
  1184. }
  1185. /**
  1186. * fcoe_dev_setup() - cleanup link change notification interface
  1187. */
  1188. static void fcoe_dev_cleanup(void)
  1189. {
  1190. unregister_netdevice_notifier(&fcoe_notifier);
  1191. }
  1192. /**
  1193. * fcoe_device_notification() - netdev event notification callback
  1194. * @notifier: context of the notification
  1195. * @event: type of event
  1196. * @ptr: fixed array for output parsed ifname
  1197. *
  1198. * This function is called by the ethernet driver in case of link change event
  1199. *
  1200. * Returns: 0 for success
  1201. */
  1202. static int fcoe_device_notification(struct notifier_block *notifier,
  1203. ulong event, void *ptr)
  1204. {
  1205. struct fc_lport *lp = NULL;
  1206. struct net_device *real_dev = ptr;
  1207. struct fcoe_softc *fc;
  1208. struct fcoe_dev_stats *stats;
  1209. u32 link_possible = 1;
  1210. u32 mfs;
  1211. int rc = NOTIFY_OK;
  1212. read_lock(&fcoe_hostlist_lock);
  1213. list_for_each_entry(fc, &fcoe_hostlist, list) {
  1214. if (fc->real_dev == real_dev) {
  1215. lp = fc->ctlr.lp;
  1216. break;
  1217. }
  1218. }
  1219. read_unlock(&fcoe_hostlist_lock);
  1220. if (lp == NULL) {
  1221. rc = NOTIFY_DONE;
  1222. goto out;
  1223. }
  1224. switch (event) {
  1225. case NETDEV_DOWN:
  1226. case NETDEV_GOING_DOWN:
  1227. link_possible = 0;
  1228. break;
  1229. case NETDEV_UP:
  1230. case NETDEV_CHANGE:
  1231. break;
  1232. case NETDEV_CHANGEMTU:
  1233. mfs = fc->real_dev->mtu -
  1234. (sizeof(struct fcoe_hdr) +
  1235. sizeof(struct fcoe_crc_eof));
  1236. if (mfs >= FC_MIN_MAX_FRAME)
  1237. fc_set_mfs(lp, mfs);
  1238. break;
  1239. case NETDEV_REGISTER:
  1240. break;
  1241. default:
  1242. FC_DBG("Unknown event %ld from netdev netlink\n", event);
  1243. }
  1244. if (link_possible && !fcoe_link_ok(lp))
  1245. fcoe_ctlr_link_up(&fc->ctlr);
  1246. else if (fcoe_ctlr_link_down(&fc->ctlr)) {
  1247. stats = fc_lport_get_stats(lp);
  1248. stats->LinkFailureCount++;
  1249. fcoe_clean_pending_queue(lp);
  1250. }
  1251. out:
  1252. return rc;
  1253. }
  1254. /**
  1255. * fcoe_if_to_netdev() - parse a name buffer to get netdev
  1256. * @ifname: fixed array for output parsed ifname
  1257. * @buffer: incoming buffer to be copied
  1258. *
  1259. * Returns: NULL or ptr to netdeive
  1260. */
  1261. static struct net_device *fcoe_if_to_netdev(const char *buffer)
  1262. {
  1263. char *cp;
  1264. char ifname[IFNAMSIZ + 2];
  1265. if (buffer) {
  1266. strlcpy(ifname, buffer, IFNAMSIZ);
  1267. cp = ifname + strlen(ifname);
  1268. while (--cp >= ifname && *cp == '\n')
  1269. *cp = '\0';
  1270. return dev_get_by_name(&init_net, ifname);
  1271. }
  1272. return NULL;
  1273. }
  1274. /**
  1275. * fcoe_netdev_to_module_owner() - finds out the nic drive moddule of the netdev
  1276. * @netdev: the target netdev
  1277. *
  1278. * Returns: ptr to the struct module, NULL for failure
  1279. */
  1280. static struct module *
  1281. fcoe_netdev_to_module_owner(const struct net_device *netdev)
  1282. {
  1283. struct device *dev;
  1284. if (!netdev)
  1285. return NULL;
  1286. dev = netdev->dev.parent;
  1287. if (!dev)
  1288. return NULL;
  1289. if (!dev->driver)
  1290. return NULL;
  1291. return dev->driver->owner;
  1292. }
  1293. /**
  1294. * fcoe_ethdrv_get() - Hold the Ethernet driver
  1295. * @netdev: the target netdev
  1296. *
  1297. * Holds the Ethernet driver module by try_module_get() for
  1298. * the corresponding netdev.
  1299. *
  1300. * Returns: 0 for succsss
  1301. */
  1302. static int fcoe_ethdrv_get(const struct net_device *netdev)
  1303. {
  1304. struct module *owner;
  1305. owner = fcoe_netdev_to_module_owner(netdev);
  1306. if (owner) {
  1307. printk(KERN_DEBUG "fcoe:hold driver module %s for %s\n",
  1308. module_name(owner), netdev->name);
  1309. return try_module_get(owner);
  1310. }
  1311. return -ENODEV;
  1312. }
  1313. /**
  1314. * fcoe_ethdrv_put() - Release the Ethernet driver
  1315. * @netdev: the target netdev
  1316. *
  1317. * Releases the Ethernet driver module by module_put for
  1318. * the corresponding netdev.
  1319. *
  1320. * Returns: 0 for succsss
  1321. */
  1322. static int fcoe_ethdrv_put(const struct net_device *netdev)
  1323. {
  1324. struct module *owner;
  1325. owner = fcoe_netdev_to_module_owner(netdev);
  1326. if (owner) {
  1327. printk(KERN_DEBUG "fcoe:release driver module %s for %s\n",
  1328. module_name(owner), netdev->name);
  1329. module_put(owner);
  1330. return 0;
  1331. }
  1332. return -ENODEV;
  1333. }
  1334. /**
  1335. * fcoe_destroy() - handles the destroy from sysfs
  1336. * @buffer: expcted to be a eth if name
  1337. * @kp: associated kernel param
  1338. *
  1339. * Returns: 0 for success
  1340. */
  1341. static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
  1342. {
  1343. int rc;
  1344. struct net_device *netdev;
  1345. netdev = fcoe_if_to_netdev(buffer);
  1346. if (!netdev) {
  1347. rc = -ENODEV;
  1348. goto out_nodev;
  1349. }
  1350. /* look for existing lport */
  1351. if (!fcoe_hostlist_lookup(netdev)) {
  1352. rc = -ENODEV;
  1353. goto out_putdev;
  1354. }
  1355. rc = fcoe_if_destroy(netdev);
  1356. if (rc) {
  1357. printk(KERN_ERR "fcoe: fcoe_if_destroy(%s) failed\n",
  1358. netdev->name);
  1359. rc = -EIO;
  1360. goto out_putdev;
  1361. }
  1362. fcoe_ethdrv_put(netdev);
  1363. rc = 0;
  1364. out_putdev:
  1365. dev_put(netdev);
  1366. out_nodev:
  1367. return rc;
  1368. }
  1369. /**
  1370. * fcoe_create() - Handles the create call from sysfs
  1371. * @buffer: expcted to be a eth if name
  1372. * @kp: associated kernel param
  1373. *
  1374. * Returns: 0 for success
  1375. */
  1376. static int fcoe_create(const char *buffer, struct kernel_param *kp)
  1377. {
  1378. int rc;
  1379. struct net_device *netdev;
  1380. netdev = fcoe_if_to_netdev(buffer);
  1381. if (!netdev) {
  1382. rc = -ENODEV;
  1383. goto out_nodev;
  1384. }
  1385. /* look for existing lport */
  1386. if (fcoe_hostlist_lookup(netdev)) {
  1387. rc = -EEXIST;
  1388. goto out_putdev;
  1389. }
  1390. fcoe_ethdrv_get(netdev);
  1391. rc = fcoe_if_create(netdev);
  1392. if (rc) {
  1393. printk(KERN_ERR "fcoe: fcoe_if_create(%s) failed\n",
  1394. netdev->name);
  1395. fcoe_ethdrv_put(netdev);
  1396. rc = -EIO;
  1397. goto out_putdev;
  1398. }
  1399. rc = 0;
  1400. out_putdev:
  1401. dev_put(netdev);
  1402. out_nodev:
  1403. return rc;
  1404. }
  1405. module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR);
  1406. __MODULE_PARM_TYPE(create, "string");
  1407. MODULE_PARM_DESC(create, "Create fcoe port using net device passed in.");
  1408. module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR);
  1409. __MODULE_PARM_TYPE(destroy, "string");
  1410. MODULE_PARM_DESC(destroy, "Destroy fcoe port");
  1411. /**
  1412. * fcoe_link_ok() - Check if link is ok for the fc_lport
  1413. * @lp: ptr to the fc_lport
  1414. *
  1415. * Any permanently-disqualifying conditions have been previously checked.
  1416. * This also updates the speed setting, which may change with link for 100/1000.
  1417. *
  1418. * This function should probably be checking for PAUSE support at some point
  1419. * in the future. Currently Per-priority-pause is not determinable using
  1420. * ethtool, so we shouldn't be restrictive until that problem is resolved.
  1421. *
  1422. * Returns: 0 if link is OK for use by FCoE.
  1423. *
  1424. */
  1425. int fcoe_link_ok(struct fc_lport *lp)
  1426. {
  1427. struct fcoe_softc *fc = lport_priv(lp);
  1428. struct net_device *dev = fc->real_dev;
  1429. struct ethtool_cmd ecmd = { ETHTOOL_GSET };
  1430. int rc = 0;
  1431. if ((dev->flags & IFF_UP) && netif_carrier_ok(dev)) {
  1432. dev = fc->phys_dev;
  1433. if (dev->ethtool_ops->get_settings) {
  1434. dev->ethtool_ops->get_settings(dev, &ecmd);
  1435. lp->link_supported_speeds &=
  1436. ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
  1437. if (ecmd.supported & (SUPPORTED_1000baseT_Half |
  1438. SUPPORTED_1000baseT_Full))
  1439. lp->link_supported_speeds |= FC_PORTSPEED_1GBIT;
  1440. if (ecmd.supported & SUPPORTED_10000baseT_Full)
  1441. lp->link_supported_speeds |=
  1442. FC_PORTSPEED_10GBIT;
  1443. if (ecmd.speed == SPEED_1000)
  1444. lp->link_speed = FC_PORTSPEED_1GBIT;
  1445. if (ecmd.speed == SPEED_10000)
  1446. lp->link_speed = FC_PORTSPEED_10GBIT;
  1447. }
  1448. } else
  1449. rc = -1;
  1450. return rc;
  1451. }
  1452. EXPORT_SYMBOL_GPL(fcoe_link_ok);
  1453. /**
  1454. * fcoe_percpu_clean() - Clear the pending skbs for an lport
  1455. * @lp: the fc_lport
  1456. */
  1457. void fcoe_percpu_clean(struct fc_lport *lp)
  1458. {
  1459. struct fcoe_percpu_s *pp;
  1460. struct fcoe_rcv_info *fr;
  1461. struct sk_buff_head *list;
  1462. struct sk_buff *skb, *next;
  1463. struct sk_buff *head;
  1464. unsigned int cpu;
  1465. for_each_possible_cpu(cpu) {
  1466. pp = &per_cpu(fcoe_percpu, cpu);
  1467. spin_lock_bh(&pp->fcoe_rx_list.lock);
  1468. list = &pp->fcoe_rx_list;
  1469. head = list->next;
  1470. for (skb = head; skb != (struct sk_buff *)list;
  1471. skb = next) {
  1472. next = skb->next;
  1473. fr = fcoe_dev_from_skb(skb);
  1474. if (fr->fr_dev == lp) {
  1475. __skb_unlink(skb, list);
  1476. kfree_skb(skb);
  1477. }
  1478. }
  1479. spin_unlock_bh(&pp->fcoe_rx_list.lock);
  1480. }
  1481. }
  1482. EXPORT_SYMBOL_GPL(fcoe_percpu_clean);
  1483. /**
  1484. * fcoe_clean_pending_queue() - Dequeue a skb and free it
  1485. * @lp: the corresponding fc_lport
  1486. *
  1487. * Returns: none
  1488. */
  1489. void fcoe_clean_pending_queue(struct fc_lport *lp)
  1490. {
  1491. struct fcoe_softc *fc = lport_priv(lp);
  1492. struct sk_buff *skb;
  1493. spin_lock_bh(&fc->fcoe_pending_queue.lock);
  1494. while ((skb = __skb_dequeue(&fc->fcoe_pending_queue)) != NULL) {
  1495. spin_unlock_bh(&fc->fcoe_pending_queue.lock);
  1496. kfree_skb(skb);
  1497. spin_lock_bh(&fc->fcoe_pending_queue.lock);
  1498. }
  1499. spin_unlock_bh(&fc->fcoe_pending_queue.lock);
  1500. }
  1501. EXPORT_SYMBOL_GPL(fcoe_clean_pending_queue);
  1502. /**
  1503. * fcoe_reset() - Resets the fcoe
  1504. * @shost: shost the reset is from
  1505. *
  1506. * Returns: always 0
  1507. */
  1508. int fcoe_reset(struct Scsi_Host *shost)
  1509. {
  1510. struct fc_lport *lport = shost_priv(shost);
  1511. fc_lport_reset(lport);
  1512. return 0;
  1513. }
  1514. EXPORT_SYMBOL_GPL(fcoe_reset);
  1515. /**
  1516. * fcoe_hostlist_lookup_softc() - find the corresponding lport by a given device
  1517. * @device: this is currently ptr to net_device
  1518. *
  1519. * Returns: NULL or the located fcoe_softc
  1520. */
  1521. static struct fcoe_softc *
  1522. fcoe_hostlist_lookup_softc(const struct net_device *dev)
  1523. {
  1524. struct fcoe_softc *fc;
  1525. read_lock(&fcoe_hostlist_lock);
  1526. list_for_each_entry(fc, &fcoe_hostlist, list) {
  1527. if (fc->real_dev == dev) {
  1528. read_unlock(&fcoe_hostlist_lock);
  1529. return fc;
  1530. }
  1531. }
  1532. read_unlock(&fcoe_hostlist_lock);
  1533. return NULL;
  1534. }
  1535. /**
  1536. * fcoe_hostlist_lookup() - Find the corresponding lport by netdev
  1537. * @netdev: ptr to net_device
  1538. *
  1539. * Returns: 0 for success
  1540. */
  1541. struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
  1542. {
  1543. struct fcoe_softc *fc;
  1544. fc = fcoe_hostlist_lookup_softc(netdev);
  1545. return (fc) ? fc->ctlr.lp : NULL;
  1546. }
  1547. EXPORT_SYMBOL_GPL(fcoe_hostlist_lookup);
  1548. /**
  1549. * fcoe_hostlist_add() - Add a lport to lports list
  1550. * @lp: ptr to the fc_lport to badded
  1551. *
  1552. * Returns: 0 for success
  1553. */
  1554. int fcoe_hostlist_add(const struct fc_lport *lp)
  1555. {
  1556. struct fcoe_softc *fc;
  1557. fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
  1558. if (!fc) {
  1559. fc = lport_priv(lp);
  1560. write_lock_bh(&fcoe_hostlist_lock);
  1561. list_add_tail(&fc->list, &fcoe_hostlist);
  1562. write_unlock_bh(&fcoe_hostlist_lock);
  1563. }
  1564. return 0;
  1565. }
  1566. EXPORT_SYMBOL_GPL(fcoe_hostlist_add);
  1567. /**
  1568. * fcoe_hostlist_remove() - remove a lport from lports list
  1569. * @lp: ptr to the fc_lport to badded
  1570. *
  1571. * Returns: 0 for success
  1572. */
  1573. int fcoe_hostlist_remove(const struct fc_lport *lp)
  1574. {
  1575. struct fcoe_softc *fc;
  1576. fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
  1577. BUG_ON(!fc);
  1578. write_lock_bh(&fcoe_hostlist_lock);
  1579. list_del(&fc->list);
  1580. write_unlock_bh(&fcoe_hostlist_lock);
  1581. return 0;
  1582. }
  1583. EXPORT_SYMBOL_GPL(fcoe_hostlist_remove);
  1584. /**
  1585. * fcoe_init() - fcoe module loading initialization
  1586. *
  1587. * Returns 0 on success, negative on failure
  1588. */
  1589. static int __init fcoe_init(void)
  1590. {
  1591. unsigned int cpu;
  1592. int rc = 0;
  1593. struct fcoe_percpu_s *p;
  1594. INIT_LIST_HEAD(&fcoe_hostlist);
  1595. rwlock_init(&fcoe_hostlist_lock);
  1596. for_each_possible_cpu(cpu) {
  1597. p = &per_cpu(fcoe_percpu, cpu);
  1598. skb_queue_head_init(&p->fcoe_rx_list);
  1599. }
  1600. for_each_online_cpu(cpu)
  1601. fcoe_percpu_thread_create(cpu);
  1602. /* Initialize per CPU interrupt thread */
  1603. rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
  1604. if (rc)
  1605. goto out_free;
  1606. /* Setup link change notification */
  1607. fcoe_dev_setup();
  1608. setup_timer(&fcoe_timer, fcoe_watchdog, 0);
  1609. mod_timer(&fcoe_timer, jiffies + (10 * HZ));
  1610. fcoe_if_init();
  1611. return 0;
  1612. out_free:
  1613. for_each_online_cpu(cpu) {
  1614. fcoe_percpu_thread_destroy(cpu);
  1615. }
  1616. return rc;
  1617. }
  1618. module_init(fcoe_init);
  1619. /**
  1620. * fcoe_exit() - fcoe module unloading cleanup
  1621. *
  1622. * Returns 0 on success, negative on failure
  1623. */
  1624. static void __exit fcoe_exit(void)
  1625. {
  1626. unsigned int cpu;
  1627. struct fcoe_softc *fc, *tmp;
  1628. fcoe_dev_cleanup();
  1629. /* Stop the timer */
  1630. del_timer_sync(&fcoe_timer);
  1631. /* releases the associated fcoe hosts */
  1632. list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list)
  1633. fcoe_if_destroy(fc->real_dev);
  1634. unregister_hotcpu_notifier(&fcoe_cpu_notifier);
  1635. for_each_online_cpu(cpu) {
  1636. fcoe_percpu_thread_destroy(cpu);
  1637. }
  1638. /* detach from scsi transport */
  1639. fcoe_if_exit();
  1640. }
  1641. module_exit(fcoe_exit);