fcoe.c 46 KB

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