fcoe.c 45 KB

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