nes.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. /*
  2. * Copyright (c) 2006 - 2011 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <linux/module.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/etherdevice.h>
  37. #include <linux/ethtool.h>
  38. #include <linux/mii.h>
  39. #include <linux/if_vlan.h>
  40. #include <linux/crc32.h>
  41. #include <linux/in.h>
  42. #include <linux/fs.h>
  43. #include <linux/init.h>
  44. #include <linux/if_arp.h>
  45. #include <linux/highmem.h>
  46. #include <linux/slab.h>
  47. #include <asm/io.h>
  48. #include <asm/irq.h>
  49. #include <asm/byteorder.h>
  50. #include <rdma/ib_smi.h>
  51. #include <rdma/ib_verbs.h>
  52. #include <rdma/ib_pack.h>
  53. #include <rdma/iw_cm.h>
  54. #include "nes.h"
  55. #include <net/netevent.h>
  56. #include <net/neighbour.h>
  57. #include <linux/route.h>
  58. #include <net/ip_fib.h>
  59. MODULE_AUTHOR("NetEffect");
  60. MODULE_DESCRIPTION("NetEffect RNIC Low-level iWARP Driver");
  61. MODULE_LICENSE("Dual BSD/GPL");
  62. MODULE_VERSION(DRV_VERSION);
  63. int max_mtu = 9000;
  64. int interrupt_mod_interval = 0;
  65. /* Interoperability */
  66. int mpa_version = 1;
  67. module_param(mpa_version, int, 0644);
  68. MODULE_PARM_DESC(mpa_version, "MPA version to be used int MPA Req/Resp (0 or 1)");
  69. /* Interoperability */
  70. int disable_mpa_crc = 0;
  71. module_param(disable_mpa_crc, int, 0644);
  72. MODULE_PARM_DESC(disable_mpa_crc, "Disable checking of MPA CRC");
  73. unsigned int send_first = 0;
  74. module_param(send_first, int, 0644);
  75. MODULE_PARM_DESC(send_first, "Send RDMA Message First on Active Connection");
  76. unsigned int nes_drv_opt = NES_DRV_OPT_DISABLE_INT_MOD | NES_DRV_OPT_ENABLE_PAU;
  77. module_param(nes_drv_opt, int, 0644);
  78. MODULE_PARM_DESC(nes_drv_opt, "Driver option parameters");
  79. unsigned int nes_debug_level = 0;
  80. module_param_named(debug_level, nes_debug_level, uint, 0644);
  81. MODULE_PARM_DESC(debug_level, "Enable debug output level");
  82. unsigned int wqm_quanta = 0x10000;
  83. module_param(wqm_quanta, int, 0644);
  84. MODULE_PARM_DESC(wqm_quanta, "WQM quanta");
  85. static bool limit_maxrdreqsz;
  86. module_param(limit_maxrdreqsz, bool, 0644);
  87. MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
  88. LIST_HEAD(nes_adapter_list);
  89. static LIST_HEAD(nes_dev_list);
  90. atomic_t qps_destroyed;
  91. static unsigned int ee_flsh_adapter;
  92. static unsigned int sysfs_nonidx_addr;
  93. static unsigned int sysfs_idx_addr;
  94. static struct pci_device_id nes_pci_table[] = {
  95. { PCI_VDEVICE(NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020), },
  96. { PCI_VDEVICE(NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020_KR), },
  97. {0}
  98. };
  99. MODULE_DEVICE_TABLE(pci, nes_pci_table);
  100. static int nes_inetaddr_event(struct notifier_block *, unsigned long, void *);
  101. static int nes_net_event(struct notifier_block *, unsigned long, void *);
  102. static int nes_notifiers_registered;
  103. static struct notifier_block nes_inetaddr_notifier = {
  104. .notifier_call = nes_inetaddr_event
  105. };
  106. static struct notifier_block nes_net_notifier = {
  107. .notifier_call = nes_net_event
  108. };
  109. /**
  110. * nes_inetaddr_event
  111. */
  112. static int nes_inetaddr_event(struct notifier_block *notifier,
  113. unsigned long event, void *ptr)
  114. {
  115. struct in_ifaddr *ifa = ptr;
  116. struct net_device *event_netdev = ifa->ifa_dev->dev;
  117. struct nes_device *nesdev;
  118. struct net_device *netdev;
  119. struct nes_vnic *nesvnic;
  120. unsigned int is_bonded;
  121. nes_debug(NES_DBG_NETDEV, "nes_inetaddr_event: ip address %pI4, netmask %pI4.\n",
  122. &ifa->ifa_address, &ifa->ifa_mask);
  123. list_for_each_entry(nesdev, &nes_dev_list, list) {
  124. nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p. (%s)\n",
  125. nesdev, nesdev->netdev[0]->name);
  126. netdev = nesdev->netdev[0];
  127. nesvnic = netdev_priv(netdev);
  128. is_bonded = netif_is_bond_slave(netdev) &&
  129. (netdev->master == event_netdev);
  130. if ((netdev == event_netdev) || is_bonded) {
  131. if (nesvnic->rdma_enabled == 0) {
  132. nes_debug(NES_DBG_NETDEV, "Returning without processing event for %s since"
  133. " RDMA is not enabled.\n",
  134. netdev->name);
  135. return NOTIFY_OK;
  136. }
  137. /* we have ifa->ifa_address/mask here if we need it */
  138. switch (event) {
  139. case NETDEV_DOWN:
  140. nes_debug(NES_DBG_NETDEV, "event:DOWN\n");
  141. nes_write_indexed(nesdev,
  142. NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)), 0);
  143. nes_manage_arp_cache(netdev, netdev->dev_addr,
  144. ntohl(nesvnic->local_ipaddr), NES_ARP_DELETE);
  145. nesvnic->local_ipaddr = 0;
  146. if (is_bonded)
  147. continue;
  148. else
  149. return NOTIFY_OK;
  150. break;
  151. case NETDEV_UP:
  152. nes_debug(NES_DBG_NETDEV, "event:UP\n");
  153. if (nesvnic->local_ipaddr != 0) {
  154. nes_debug(NES_DBG_NETDEV, "Interface already has local_ipaddr\n");
  155. return NOTIFY_OK;
  156. }
  157. /* fall through */
  158. case NETDEV_CHANGEADDR:
  159. /* Add the address to the IP table */
  160. if (netdev->master)
  161. nesvnic->local_ipaddr =
  162. ((struct in_device *)netdev->master->ip_ptr)->ifa_list->ifa_address;
  163. else
  164. nesvnic->local_ipaddr = ifa->ifa_address;
  165. nes_write_indexed(nesdev,
  166. NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)),
  167. ntohl(nesvnic->local_ipaddr));
  168. nes_manage_arp_cache(netdev, netdev->dev_addr,
  169. ntohl(nesvnic->local_ipaddr), NES_ARP_ADD);
  170. if (is_bonded)
  171. continue;
  172. else
  173. return NOTIFY_OK;
  174. break;
  175. default:
  176. break;
  177. }
  178. }
  179. }
  180. return NOTIFY_DONE;
  181. }
  182. /**
  183. * nes_net_event
  184. */
  185. static int nes_net_event(struct notifier_block *notifier,
  186. unsigned long event, void *ptr)
  187. {
  188. struct neighbour *neigh = ptr;
  189. struct nes_device *nesdev;
  190. struct net_device *netdev;
  191. struct nes_vnic *nesvnic;
  192. switch (event) {
  193. case NETEVENT_NEIGH_UPDATE:
  194. list_for_each_entry(nesdev, &nes_dev_list, list) {
  195. /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
  196. netdev = nesdev->netdev[0];
  197. nesvnic = netdev_priv(netdev);
  198. if (netdev == neigh->dev) {
  199. if (nesvnic->rdma_enabled == 0) {
  200. nes_debug(NES_DBG_NETDEV, "Skipping device %s since no RDMA\n",
  201. netdev->name);
  202. } else {
  203. if (neigh->nud_state & NUD_VALID) {
  204. nes_manage_arp_cache(neigh->dev, neigh->ha,
  205. ntohl(*(__be32 *)neigh->primary_key), NES_ARP_ADD);
  206. } else {
  207. nes_manage_arp_cache(neigh->dev, neigh->ha,
  208. ntohl(*(__be32 *)neigh->primary_key), NES_ARP_DELETE);
  209. }
  210. }
  211. return NOTIFY_OK;
  212. }
  213. }
  214. break;
  215. default:
  216. nes_debug(NES_DBG_NETDEV, "NETEVENT_ %lu undefined\n", event);
  217. break;
  218. }
  219. return NOTIFY_DONE;
  220. }
  221. /**
  222. * nes_add_ref
  223. */
  224. void nes_add_ref(struct ib_qp *ibqp)
  225. {
  226. struct nes_qp *nesqp;
  227. nesqp = to_nesqp(ibqp);
  228. nes_debug(NES_DBG_QP, "Bumping refcount for QP%u. Pre-inc value = %u\n",
  229. ibqp->qp_num, atomic_read(&nesqp->refcount));
  230. atomic_inc(&nesqp->refcount);
  231. }
  232. static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
  233. {
  234. unsigned long flags;
  235. struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
  236. struct nes_adapter *nesadapter = nesdev->nesadapter;
  237. atomic_inc(&qps_destroyed);
  238. /* Free the control structures */
  239. if (nesqp->pbl_vbase) {
  240. pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
  241. nesqp->hwqp.q2_vbase, nesqp->hwqp.q2_pbase);
  242. spin_lock_irqsave(&nesadapter->pbl_lock, flags);
  243. nesadapter->free_256pbl++;
  244. spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
  245. pci_free_consistent(nesdev->pcidev, 256, nesqp->pbl_vbase, nesqp->pbl_pbase);
  246. nesqp->pbl_vbase = NULL;
  247. } else {
  248. pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
  249. nesqp->hwqp.sq_vbase, nesqp->hwqp.sq_pbase);
  250. }
  251. nes_free_resource(nesadapter, nesadapter->allocated_qps, nesqp->hwqp.qp_id);
  252. nesadapter->qp_table[nesqp->hwqp.qp_id-NES_FIRST_QPN] = NULL;
  253. kfree(nesqp->allocated_buffer);
  254. }
  255. /**
  256. * nes_rem_ref
  257. */
  258. void nes_rem_ref(struct ib_qp *ibqp)
  259. {
  260. u64 u64temp;
  261. struct nes_qp *nesqp;
  262. struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
  263. struct nes_device *nesdev = nesvnic->nesdev;
  264. struct nes_hw_cqp_wqe *cqp_wqe;
  265. struct nes_cqp_request *cqp_request;
  266. u32 opcode;
  267. nesqp = to_nesqp(ibqp);
  268. if (atomic_read(&nesqp->refcount) == 0) {
  269. printk(KERN_INFO PFX "%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
  270. __func__, ibqp->qp_num, nesqp->last_aeq);
  271. BUG();
  272. }
  273. if (atomic_dec_and_test(&nesqp->refcount)) {
  274. if (nesqp->pau_mode)
  275. nes_destroy_pau_qp(nesdev, nesqp);
  276. /* Destroy the QP */
  277. cqp_request = nes_get_cqp_request(nesdev);
  278. if (cqp_request == NULL) {
  279. nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
  280. return;
  281. }
  282. cqp_request->waiting = 0;
  283. cqp_request->callback = 1;
  284. cqp_request->cqp_callback = nes_cqp_rem_ref_callback;
  285. cqp_request->cqp_callback_pointer = nesqp;
  286. cqp_wqe = &cqp_request->cqp_wqe;
  287. nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
  288. opcode = NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_IWARP;
  289. if (nesqp->hte_added) {
  290. opcode |= NES_CQP_QP_DEL_HTE;
  291. nesqp->hte_added = 0;
  292. }
  293. set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
  294. set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
  295. u64temp = (u64)nesqp->nesqp_context_pbase;
  296. set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
  297. nes_post_cqp_request(nesdev, cqp_request);
  298. }
  299. }
  300. /**
  301. * nes_get_qp
  302. */
  303. struct ib_qp *nes_get_qp(struct ib_device *device, int qpn)
  304. {
  305. struct nes_vnic *nesvnic = to_nesvnic(device);
  306. struct nes_device *nesdev = nesvnic->nesdev;
  307. struct nes_adapter *nesadapter = nesdev->nesadapter;
  308. if ((qpn < NES_FIRST_QPN) || (qpn >= (NES_FIRST_QPN + nesadapter->max_qp)))
  309. return NULL;
  310. return &nesadapter->qp_table[qpn - NES_FIRST_QPN]->ibqp;
  311. }
  312. /**
  313. * nes_print_macaddr
  314. */
  315. static void nes_print_macaddr(struct net_device *netdev)
  316. {
  317. nes_debug(NES_DBG_INIT, "%s: %pM, IRQ %u\n",
  318. netdev->name, netdev->dev_addr, netdev->irq);
  319. }
  320. /**
  321. * nes_interrupt - handle interrupts
  322. */
  323. static irqreturn_t nes_interrupt(int irq, void *dev_id)
  324. {
  325. struct nes_device *nesdev = (struct nes_device *)dev_id;
  326. int handled = 0;
  327. u32 int_mask;
  328. u32 int_req;
  329. u32 int_stat;
  330. u32 intf_int_stat;
  331. u32 timer_stat;
  332. if (nesdev->msi_enabled) {
  333. /* No need to read the interrupt pending register if msi is enabled */
  334. handled = 1;
  335. } else {
  336. if (unlikely(nesdev->nesadapter->hw_rev == NE020_REV)) {
  337. /* Master interrupt enable provides synchronization for kicking off bottom half
  338. when interrupt sharing is going on */
  339. int_mask = nes_read32(nesdev->regs + NES_INT_MASK);
  340. if (int_mask & 0x80000000) {
  341. /* Check interrupt status to see if this might be ours */
  342. int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
  343. int_req = nesdev->int_req;
  344. if (int_stat&int_req) {
  345. /* if interesting CEQ or AEQ is pending, claim the interrupt */
  346. if ((int_stat&int_req) & (~(NES_INT_TIMER|NES_INT_INTF))) {
  347. handled = 1;
  348. } else {
  349. if (((int_stat & int_req) & NES_INT_TIMER) == NES_INT_TIMER) {
  350. /* Timer might be running but might be for another function */
  351. timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
  352. if ((timer_stat & nesdev->timer_int_req) != 0) {
  353. handled = 1;
  354. }
  355. }
  356. if ((((int_stat & int_req) & NES_INT_INTF) == NES_INT_INTF) &&
  357. (handled == 0)) {
  358. intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
  359. if ((intf_int_stat & nesdev->intf_int_req) != 0) {
  360. handled = 1;
  361. }
  362. }
  363. }
  364. if (handled) {
  365. nes_write32(nesdev->regs+NES_INT_MASK, int_mask & (~0x80000000));
  366. int_mask = nes_read32(nesdev->regs+NES_INT_MASK);
  367. /* Save off the status to save an additional read */
  368. nesdev->int_stat = int_stat;
  369. nesdev->napi_isr_ran = 1;
  370. }
  371. }
  372. }
  373. } else {
  374. handled = nes_read32(nesdev->regs+NES_INT_PENDING);
  375. }
  376. }
  377. if (handled) {
  378. if (nes_napi_isr(nesdev) == 0) {
  379. tasklet_schedule(&nesdev->dpc_tasklet);
  380. }
  381. return IRQ_HANDLED;
  382. } else {
  383. return IRQ_NONE;
  384. }
  385. }
  386. /**
  387. * nes_probe - Device initialization
  388. */
  389. static int __devinit nes_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
  390. {
  391. struct net_device *netdev = NULL;
  392. struct nes_device *nesdev = NULL;
  393. int ret = 0;
  394. void __iomem *mmio_regs = NULL;
  395. u8 hw_rev;
  396. assert(pcidev != NULL);
  397. assert(ent != NULL);
  398. printk(KERN_INFO PFX "NetEffect RNIC driver v%s loading. (%s)\n",
  399. DRV_VERSION, pci_name(pcidev));
  400. ret = pci_enable_device(pcidev);
  401. if (ret) {
  402. printk(KERN_ERR PFX "Unable to enable PCI device. (%s)\n", pci_name(pcidev));
  403. goto bail0;
  404. }
  405. nes_debug(NES_DBG_INIT, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
  406. (long unsigned int)pci_resource_start(pcidev, BAR_0),
  407. (long unsigned int)pci_resource_len(pcidev, BAR_0));
  408. nes_debug(NES_DBG_INIT, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
  409. (long unsigned int)pci_resource_start(pcidev, BAR_1),
  410. (long unsigned int)pci_resource_len(pcidev, BAR_1));
  411. /* Make sure PCI base addr are MMIO */
  412. if (!(pci_resource_flags(pcidev, BAR_0) & IORESOURCE_MEM) ||
  413. !(pci_resource_flags(pcidev, BAR_1) & IORESOURCE_MEM)) {
  414. printk(KERN_ERR PFX "PCI regions not an MMIO resource\n");
  415. ret = -ENODEV;
  416. goto bail1;
  417. }
  418. /* Reserve PCI I/O and memory resources */
  419. ret = pci_request_regions(pcidev, DRV_NAME);
  420. if (ret) {
  421. printk(KERN_ERR PFX "Unable to request regions. (%s)\n", pci_name(pcidev));
  422. goto bail1;
  423. }
  424. if ((sizeof(dma_addr_t) > 4)) {
  425. ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
  426. if (ret < 0) {
  427. printk(KERN_ERR PFX "64b DMA mask configuration failed\n");
  428. goto bail2;
  429. }
  430. ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
  431. if (ret) {
  432. printk(KERN_ERR PFX "64b DMA consistent mask configuration failed\n");
  433. goto bail2;
  434. }
  435. } else {
  436. ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
  437. if (ret < 0) {
  438. printk(KERN_ERR PFX "32b DMA mask configuration failed\n");
  439. goto bail2;
  440. }
  441. ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
  442. if (ret) {
  443. printk(KERN_ERR PFX "32b DMA consistent mask configuration failed\n");
  444. goto bail2;
  445. }
  446. }
  447. pci_set_master(pcidev);
  448. /* Allocate hardware structure */
  449. nesdev = kzalloc(sizeof(struct nes_device), GFP_KERNEL);
  450. if (!nesdev) {
  451. printk(KERN_ERR PFX "%s: Unable to alloc hardware struct\n", pci_name(pcidev));
  452. ret = -ENOMEM;
  453. goto bail2;
  454. }
  455. nes_debug(NES_DBG_INIT, "Allocated nes device at %p\n", nesdev);
  456. nesdev->pcidev = pcidev;
  457. pci_set_drvdata(pcidev, nesdev);
  458. pci_read_config_byte(pcidev, 0x0008, &hw_rev);
  459. nes_debug(NES_DBG_INIT, "hw_rev=%u\n", hw_rev);
  460. spin_lock_init(&nesdev->indexed_regs_lock);
  461. /* Remap the PCI registers in adapter BAR0 to kernel VA space */
  462. mmio_regs = ioremap_nocache(pci_resource_start(pcidev, BAR_0),
  463. pci_resource_len(pcidev, BAR_0));
  464. if (mmio_regs == NULL) {
  465. printk(KERN_ERR PFX "Unable to remap BAR0\n");
  466. ret = -EIO;
  467. goto bail3;
  468. }
  469. nesdev->regs = mmio_regs;
  470. nesdev->index_reg = 0x50 + (PCI_FUNC(pcidev->devfn)*8) + mmio_regs;
  471. /* Ensure interrupts are disabled */
  472. nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
  473. if (nes_drv_opt & NES_DRV_OPT_ENABLE_MSI) {
  474. if (!pci_enable_msi(nesdev->pcidev)) {
  475. nesdev->msi_enabled = 1;
  476. nes_debug(NES_DBG_INIT, "MSI is enabled for device %s\n",
  477. pci_name(pcidev));
  478. } else {
  479. nes_debug(NES_DBG_INIT, "MSI is disabled by linux for device %s\n",
  480. pci_name(pcidev));
  481. }
  482. } else {
  483. nes_debug(NES_DBG_INIT, "MSI not requested due to driver options for device %s\n",
  484. pci_name(pcidev));
  485. }
  486. nesdev->csr_start = pci_resource_start(nesdev->pcidev, BAR_0);
  487. nesdev->doorbell_region = pci_resource_start(nesdev->pcidev, BAR_1);
  488. /* Init the adapter */
  489. nesdev->nesadapter = nes_init_adapter(nesdev, hw_rev);
  490. if (!nesdev->nesadapter) {
  491. printk(KERN_ERR PFX "Unable to initialize adapter.\n");
  492. ret = -ENOMEM;
  493. goto bail5;
  494. }
  495. nesdev->nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
  496. nesdev->nesadapter->wqm_quanta = wqm_quanta;
  497. /* nesdev->base_doorbell_index =
  498. nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
  499. nesdev->base_doorbell_index = 1;
  500. nesdev->doorbell_start = nesdev->nesadapter->doorbell_start;
  501. if (nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_PUMA_1G) {
  502. switch (PCI_FUNC(nesdev->pcidev->devfn) %
  503. nesdev->nesadapter->port_count) {
  504. case 1:
  505. nesdev->mac_index = 2;
  506. break;
  507. case 2:
  508. nesdev->mac_index = 1;
  509. break;
  510. case 3:
  511. nesdev->mac_index = 3;
  512. break;
  513. case 0:
  514. default:
  515. nesdev->mac_index = 0;
  516. }
  517. } else {
  518. nesdev->mac_index = PCI_FUNC(nesdev->pcidev->devfn) %
  519. nesdev->nesadapter->port_count;
  520. }
  521. if ((limit_maxrdreqsz ||
  522. ((nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_GLADIUS) &&
  523. (hw_rev == NE020_REV1))) &&
  524. (pcie_get_readrq(pcidev) > 256)) {
  525. if (pcie_set_readrq(pcidev, 256))
  526. printk(KERN_ERR PFX "Unable to set max read request"
  527. " to 256 bytes\n");
  528. else
  529. nes_debug(NES_DBG_INIT, "Max read request size set"
  530. " to 256 bytes\n");
  531. }
  532. tasklet_init(&nesdev->dpc_tasklet, nes_dpc, (unsigned long)nesdev);
  533. /* bring up the Control QP */
  534. if (nes_init_cqp(nesdev)) {
  535. ret = -ENODEV;
  536. goto bail6;
  537. }
  538. /* Arm the CCQ */
  539. nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
  540. PCI_FUNC(nesdev->pcidev->devfn));
  541. nes_read32(nesdev->regs+NES_CQE_ALLOC);
  542. /* Enable the interrupts */
  543. nesdev->int_req = (0x101 << PCI_FUNC(nesdev->pcidev->devfn)) |
  544. (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
  545. if (PCI_FUNC(nesdev->pcidev->devfn) < 4) {
  546. nesdev->int_req |= (1 << (PCI_FUNC(nesdev->mac_index)+24));
  547. }
  548. /* TODO: This really should be the first driver to load, not function 0 */
  549. if (PCI_FUNC(nesdev->pcidev->devfn) == 0) {
  550. /* pick up PCI and critical errors if the first driver to load */
  551. nesdev->intf_int_req = NES_INTF_INT_PCIERR | NES_INTF_INT_CRITERR;
  552. nesdev->int_req |= NES_INT_INTF;
  553. } else {
  554. nesdev->intf_int_req = 0;
  555. }
  556. nesdev->intf_int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
  557. nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS0, 0);
  558. nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 0);
  559. nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS2, 0x00001265);
  560. nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS4, 0x18021804);
  561. nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS3, 0x17801790);
  562. /* deal with both periodic and one_shot */
  563. nesdev->timer_int_req = 0x101 << PCI_FUNC(nesdev->pcidev->devfn);
  564. nesdev->nesadapter->timer_int_req |= nesdev->timer_int_req;
  565. nes_debug(NES_DBG_INIT, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
  566. PCI_FUNC(nesdev->pcidev->devfn),
  567. nesdev->timer_int_req, nesdev->nesadapter->timer_int_req);
  568. nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
  569. list_add_tail(&nesdev->list, &nes_dev_list);
  570. /* Request an interrupt line for the driver */
  571. ret = request_irq(pcidev->irq, nes_interrupt, IRQF_SHARED, DRV_NAME, nesdev);
  572. if (ret) {
  573. printk(KERN_ERR PFX "%s: requested IRQ %u is busy\n",
  574. pci_name(pcidev), pcidev->irq);
  575. goto bail65;
  576. }
  577. nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
  578. if (nes_notifiers_registered == 0) {
  579. register_inetaddr_notifier(&nes_inetaddr_notifier);
  580. register_netevent_notifier(&nes_net_notifier);
  581. }
  582. nes_notifiers_registered++;
  583. INIT_DELAYED_WORK(&nesdev->work, nes_recheck_link_status);
  584. /* Initialize network devices */
  585. if ((netdev = nes_netdev_init(nesdev, mmio_regs)) == NULL)
  586. goto bail7;
  587. /* Register network device */
  588. ret = register_netdev(netdev);
  589. if (ret) {
  590. printk(KERN_ERR PFX "Unable to register netdev, ret = %d\n", ret);
  591. nes_netdev_destroy(netdev);
  592. goto bail7;
  593. }
  594. nes_print_macaddr(netdev);
  595. nesdev->netdev_count++;
  596. nesdev->nesadapter->netdev_count++;
  597. printk(KERN_INFO PFX "%s: NetEffect RNIC driver successfully loaded.\n",
  598. pci_name(pcidev));
  599. return 0;
  600. bail7:
  601. printk(KERN_ERR PFX "bail7\n");
  602. while (nesdev->netdev_count > 0) {
  603. nesdev->netdev_count--;
  604. nesdev->nesadapter->netdev_count--;
  605. unregister_netdev(nesdev->netdev[nesdev->netdev_count]);
  606. nes_netdev_destroy(nesdev->netdev[nesdev->netdev_count]);
  607. }
  608. nes_debug(NES_DBG_INIT, "netdev_count=%d, nesadapter->netdev_count=%d\n",
  609. nesdev->netdev_count, nesdev->nesadapter->netdev_count);
  610. nes_notifiers_registered--;
  611. if (nes_notifiers_registered == 0) {
  612. unregister_netevent_notifier(&nes_net_notifier);
  613. unregister_inetaddr_notifier(&nes_inetaddr_notifier);
  614. }
  615. list_del(&nesdev->list);
  616. nes_destroy_cqp(nesdev);
  617. bail65:
  618. printk(KERN_ERR PFX "bail65\n");
  619. free_irq(pcidev->irq, nesdev);
  620. if (nesdev->msi_enabled) {
  621. pci_disable_msi(pcidev);
  622. }
  623. bail6:
  624. printk(KERN_ERR PFX "bail6\n");
  625. tasklet_kill(&nesdev->dpc_tasklet);
  626. /* Deallocate the Adapter Structure */
  627. nes_destroy_adapter(nesdev->nesadapter);
  628. bail5:
  629. printk(KERN_ERR PFX "bail5\n");
  630. iounmap(nesdev->regs);
  631. bail3:
  632. printk(KERN_ERR PFX "bail3\n");
  633. kfree(nesdev);
  634. bail2:
  635. pci_release_regions(pcidev);
  636. bail1:
  637. pci_disable_device(pcidev);
  638. bail0:
  639. return ret;
  640. }
  641. /**
  642. * nes_remove - unload from kernel
  643. */
  644. static void __devexit nes_remove(struct pci_dev *pcidev)
  645. {
  646. struct nes_device *nesdev = pci_get_drvdata(pcidev);
  647. struct net_device *netdev;
  648. int netdev_index = 0;
  649. unsigned long flags;
  650. if (nesdev->netdev_count) {
  651. netdev = nesdev->netdev[netdev_index];
  652. if (netdev) {
  653. netif_stop_queue(netdev);
  654. unregister_netdev(netdev);
  655. nes_netdev_destroy(netdev);
  656. nesdev->netdev[netdev_index] = NULL;
  657. nesdev->netdev_count--;
  658. nesdev->nesadapter->netdev_count--;
  659. }
  660. }
  661. nes_notifiers_registered--;
  662. if (nes_notifiers_registered == 0) {
  663. unregister_netevent_notifier(&nes_net_notifier);
  664. unregister_inetaddr_notifier(&nes_inetaddr_notifier);
  665. }
  666. list_del(&nesdev->list);
  667. nes_destroy_cqp(nesdev);
  668. free_irq(pcidev->irq, nesdev);
  669. tasklet_kill(&nesdev->dpc_tasklet);
  670. spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
  671. if (nesdev->link_recheck) {
  672. spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
  673. cancel_delayed_work_sync(&nesdev->work);
  674. } else {
  675. spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
  676. }
  677. /* Deallocate the Adapter Structure */
  678. nes_destroy_adapter(nesdev->nesadapter);
  679. if (nesdev->msi_enabled) {
  680. pci_disable_msi(pcidev);
  681. }
  682. iounmap(nesdev->regs);
  683. kfree(nesdev);
  684. /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
  685. pci_release_regions(pcidev);
  686. pci_disable_device(pcidev);
  687. pci_set_drvdata(pcidev, NULL);
  688. }
  689. static struct pci_driver nes_pci_driver = {
  690. .name = DRV_NAME,
  691. .id_table = nes_pci_table,
  692. .probe = nes_probe,
  693. .remove = __devexit_p(nes_remove),
  694. };
  695. static ssize_t nes_show_adapter(struct device_driver *ddp, char *buf)
  696. {
  697. unsigned int devfn = 0xffffffff;
  698. unsigned char bus_number = 0xff;
  699. unsigned int i = 0;
  700. struct nes_device *nesdev;
  701. list_for_each_entry(nesdev, &nes_dev_list, list) {
  702. if (i == ee_flsh_adapter) {
  703. devfn = nesdev->pcidev->devfn;
  704. bus_number = nesdev->pcidev->bus->number;
  705. break;
  706. }
  707. i++;
  708. }
  709. return snprintf(buf, PAGE_SIZE, "%x:%x\n", bus_number, devfn);
  710. }
  711. static ssize_t nes_store_adapter(struct device_driver *ddp,
  712. const char *buf, size_t count)
  713. {
  714. char *p = (char *)buf;
  715. ee_flsh_adapter = simple_strtoul(p, &p, 10);
  716. return strnlen(buf, count);
  717. }
  718. static ssize_t nes_show_ee_cmd(struct device_driver *ddp, char *buf)
  719. {
  720. u32 eeprom_cmd = 0xdead;
  721. u32 i = 0;
  722. struct nes_device *nesdev;
  723. list_for_each_entry(nesdev, &nes_dev_list, list) {
  724. if (i == ee_flsh_adapter) {
  725. eeprom_cmd = nes_read32(nesdev->regs + NES_EEPROM_COMMAND);
  726. break;
  727. }
  728. i++;
  729. }
  730. return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_cmd);
  731. }
  732. static ssize_t nes_store_ee_cmd(struct device_driver *ddp,
  733. const char *buf, size_t count)
  734. {
  735. char *p = (char *)buf;
  736. u32 val;
  737. u32 i = 0;
  738. struct nes_device *nesdev;
  739. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  740. val = simple_strtoul(p, &p, 16);
  741. list_for_each_entry(nesdev, &nes_dev_list, list) {
  742. if (i == ee_flsh_adapter) {
  743. nes_write32(nesdev->regs + NES_EEPROM_COMMAND, val);
  744. break;
  745. }
  746. i++;
  747. }
  748. }
  749. return strnlen(buf, count);
  750. }
  751. static ssize_t nes_show_ee_data(struct device_driver *ddp, char *buf)
  752. {
  753. u32 eeprom_data = 0xdead;
  754. u32 i = 0;
  755. struct nes_device *nesdev;
  756. list_for_each_entry(nesdev, &nes_dev_list, list) {
  757. if (i == ee_flsh_adapter) {
  758. eeprom_data = nes_read32(nesdev->regs + NES_EEPROM_DATA);
  759. break;
  760. }
  761. i++;
  762. }
  763. return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_data);
  764. }
  765. static ssize_t nes_store_ee_data(struct device_driver *ddp,
  766. const char *buf, size_t count)
  767. {
  768. char *p = (char *)buf;
  769. u32 val;
  770. u32 i = 0;
  771. struct nes_device *nesdev;
  772. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  773. val = simple_strtoul(p, &p, 16);
  774. list_for_each_entry(nesdev, &nes_dev_list, list) {
  775. if (i == ee_flsh_adapter) {
  776. nes_write32(nesdev->regs + NES_EEPROM_DATA, val);
  777. break;
  778. }
  779. i++;
  780. }
  781. }
  782. return strnlen(buf, count);
  783. }
  784. static ssize_t nes_show_flash_cmd(struct device_driver *ddp, char *buf)
  785. {
  786. u32 flash_cmd = 0xdead;
  787. u32 i = 0;
  788. struct nes_device *nesdev;
  789. list_for_each_entry(nesdev, &nes_dev_list, list) {
  790. if (i == ee_flsh_adapter) {
  791. flash_cmd = nes_read32(nesdev->regs + NES_FLASH_COMMAND);
  792. break;
  793. }
  794. i++;
  795. }
  796. return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_cmd);
  797. }
  798. static ssize_t nes_store_flash_cmd(struct device_driver *ddp,
  799. const char *buf, size_t count)
  800. {
  801. char *p = (char *)buf;
  802. u32 val;
  803. u32 i = 0;
  804. struct nes_device *nesdev;
  805. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  806. val = simple_strtoul(p, &p, 16);
  807. list_for_each_entry(nesdev, &nes_dev_list, list) {
  808. if (i == ee_flsh_adapter) {
  809. nes_write32(nesdev->regs + NES_FLASH_COMMAND, val);
  810. break;
  811. }
  812. i++;
  813. }
  814. }
  815. return strnlen(buf, count);
  816. }
  817. static ssize_t nes_show_flash_data(struct device_driver *ddp, char *buf)
  818. {
  819. u32 flash_data = 0xdead;
  820. u32 i = 0;
  821. struct nes_device *nesdev;
  822. list_for_each_entry(nesdev, &nes_dev_list, list) {
  823. if (i == ee_flsh_adapter) {
  824. flash_data = nes_read32(nesdev->regs + NES_FLASH_DATA);
  825. break;
  826. }
  827. i++;
  828. }
  829. return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_data);
  830. }
  831. static ssize_t nes_store_flash_data(struct device_driver *ddp,
  832. const char *buf, size_t count)
  833. {
  834. char *p = (char *)buf;
  835. u32 val;
  836. u32 i = 0;
  837. struct nes_device *nesdev;
  838. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  839. val = simple_strtoul(p, &p, 16);
  840. list_for_each_entry(nesdev, &nes_dev_list, list) {
  841. if (i == ee_flsh_adapter) {
  842. nes_write32(nesdev->regs + NES_FLASH_DATA, val);
  843. break;
  844. }
  845. i++;
  846. }
  847. }
  848. return strnlen(buf, count);
  849. }
  850. static ssize_t nes_show_nonidx_addr(struct device_driver *ddp, char *buf)
  851. {
  852. return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_nonidx_addr);
  853. }
  854. static ssize_t nes_store_nonidx_addr(struct device_driver *ddp,
  855. const char *buf, size_t count)
  856. {
  857. char *p = (char *)buf;
  858. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
  859. sysfs_nonidx_addr = simple_strtoul(p, &p, 16);
  860. return strnlen(buf, count);
  861. }
  862. static ssize_t nes_show_nonidx_data(struct device_driver *ddp, char *buf)
  863. {
  864. u32 nonidx_data = 0xdead;
  865. u32 i = 0;
  866. struct nes_device *nesdev;
  867. list_for_each_entry(nesdev, &nes_dev_list, list) {
  868. if (i == ee_flsh_adapter) {
  869. nonidx_data = nes_read32(nesdev->regs + sysfs_nonidx_addr);
  870. break;
  871. }
  872. i++;
  873. }
  874. return snprintf(buf, PAGE_SIZE, "0x%x\n", nonidx_data);
  875. }
  876. static ssize_t nes_store_nonidx_data(struct device_driver *ddp,
  877. const char *buf, size_t count)
  878. {
  879. char *p = (char *)buf;
  880. u32 val;
  881. u32 i = 0;
  882. struct nes_device *nesdev;
  883. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  884. val = simple_strtoul(p, &p, 16);
  885. list_for_each_entry(nesdev, &nes_dev_list, list) {
  886. if (i == ee_flsh_adapter) {
  887. nes_write32(nesdev->regs + sysfs_nonidx_addr, val);
  888. break;
  889. }
  890. i++;
  891. }
  892. }
  893. return strnlen(buf, count);
  894. }
  895. static ssize_t nes_show_idx_addr(struct device_driver *ddp, char *buf)
  896. {
  897. return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_idx_addr);
  898. }
  899. static ssize_t nes_store_idx_addr(struct device_driver *ddp,
  900. const char *buf, size_t count)
  901. {
  902. char *p = (char *)buf;
  903. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
  904. sysfs_idx_addr = simple_strtoul(p, &p, 16);
  905. return strnlen(buf, count);
  906. }
  907. static ssize_t nes_show_idx_data(struct device_driver *ddp, char *buf)
  908. {
  909. u32 idx_data = 0xdead;
  910. u32 i = 0;
  911. struct nes_device *nesdev;
  912. list_for_each_entry(nesdev, &nes_dev_list, list) {
  913. if (i == ee_flsh_adapter) {
  914. idx_data = nes_read_indexed(nesdev, sysfs_idx_addr);
  915. break;
  916. }
  917. i++;
  918. }
  919. return snprintf(buf, PAGE_SIZE, "0x%x\n", idx_data);
  920. }
  921. static ssize_t nes_store_idx_data(struct device_driver *ddp,
  922. const char *buf, size_t count)
  923. {
  924. char *p = (char *)buf;
  925. u32 val;
  926. u32 i = 0;
  927. struct nes_device *nesdev;
  928. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  929. val = simple_strtoul(p, &p, 16);
  930. list_for_each_entry(nesdev, &nes_dev_list, list) {
  931. if (i == ee_flsh_adapter) {
  932. nes_write_indexed(nesdev, sysfs_idx_addr, val);
  933. break;
  934. }
  935. i++;
  936. }
  937. }
  938. return strnlen(buf, count);
  939. }
  940. /**
  941. * nes_show_wqm_quanta
  942. */
  943. static ssize_t nes_show_wqm_quanta(struct device_driver *ddp, char *buf)
  944. {
  945. u32 wqm_quanta_value = 0xdead;
  946. u32 i = 0;
  947. struct nes_device *nesdev;
  948. list_for_each_entry(nesdev, &nes_dev_list, list) {
  949. if (i == ee_flsh_adapter) {
  950. wqm_quanta_value = nesdev->nesadapter->wqm_quanta;
  951. break;
  952. }
  953. i++;
  954. }
  955. return snprintf(buf, PAGE_SIZE, "0x%X\n", wqm_quanta_value);
  956. }
  957. /**
  958. * nes_store_wqm_quanta
  959. */
  960. static ssize_t nes_store_wqm_quanta(struct device_driver *ddp,
  961. const char *buf, size_t count)
  962. {
  963. unsigned long wqm_quanta_value;
  964. u32 wqm_config1;
  965. u32 i = 0;
  966. struct nes_device *nesdev;
  967. if (kstrtoul(buf, 0, &wqm_quanta_value) < 0)
  968. return -EINVAL;
  969. list_for_each_entry(nesdev, &nes_dev_list, list) {
  970. if (i == ee_flsh_adapter) {
  971. nesdev->nesadapter->wqm_quanta = wqm_quanta_value;
  972. wqm_config1 = nes_read_indexed(nesdev,
  973. NES_IDX_WQM_CONFIG1);
  974. nes_write_indexed(nesdev, NES_IDX_WQM_CONFIG1,
  975. ((wqm_quanta_value << 1) |
  976. (wqm_config1 & 0x00000001)));
  977. break;
  978. }
  979. i++;
  980. }
  981. return strnlen(buf, count);
  982. }
  983. static DRIVER_ATTR(adapter, S_IRUSR | S_IWUSR,
  984. nes_show_adapter, nes_store_adapter);
  985. static DRIVER_ATTR(eeprom_cmd, S_IRUSR | S_IWUSR,
  986. nes_show_ee_cmd, nes_store_ee_cmd);
  987. static DRIVER_ATTR(eeprom_data, S_IRUSR | S_IWUSR,
  988. nes_show_ee_data, nes_store_ee_data);
  989. static DRIVER_ATTR(flash_cmd, S_IRUSR | S_IWUSR,
  990. nes_show_flash_cmd, nes_store_flash_cmd);
  991. static DRIVER_ATTR(flash_data, S_IRUSR | S_IWUSR,
  992. nes_show_flash_data, nes_store_flash_data);
  993. static DRIVER_ATTR(nonidx_addr, S_IRUSR | S_IWUSR,
  994. nes_show_nonidx_addr, nes_store_nonidx_addr);
  995. static DRIVER_ATTR(nonidx_data, S_IRUSR | S_IWUSR,
  996. nes_show_nonidx_data, nes_store_nonidx_data);
  997. static DRIVER_ATTR(idx_addr, S_IRUSR | S_IWUSR,
  998. nes_show_idx_addr, nes_store_idx_addr);
  999. static DRIVER_ATTR(idx_data, S_IRUSR | S_IWUSR,
  1000. nes_show_idx_data, nes_store_idx_data);
  1001. static DRIVER_ATTR(wqm_quanta, S_IRUSR | S_IWUSR,
  1002. nes_show_wqm_quanta, nes_store_wqm_quanta);
  1003. static int nes_create_driver_sysfs(struct pci_driver *drv)
  1004. {
  1005. int error;
  1006. error = driver_create_file(&drv->driver, &driver_attr_adapter);
  1007. error |= driver_create_file(&drv->driver, &driver_attr_eeprom_cmd);
  1008. error |= driver_create_file(&drv->driver, &driver_attr_eeprom_data);
  1009. error |= driver_create_file(&drv->driver, &driver_attr_flash_cmd);
  1010. error |= driver_create_file(&drv->driver, &driver_attr_flash_data);
  1011. error |= driver_create_file(&drv->driver, &driver_attr_nonidx_addr);
  1012. error |= driver_create_file(&drv->driver, &driver_attr_nonidx_data);
  1013. error |= driver_create_file(&drv->driver, &driver_attr_idx_addr);
  1014. error |= driver_create_file(&drv->driver, &driver_attr_idx_data);
  1015. error |= driver_create_file(&drv->driver, &driver_attr_wqm_quanta);
  1016. return error;
  1017. }
  1018. static void nes_remove_driver_sysfs(struct pci_driver *drv)
  1019. {
  1020. driver_remove_file(&drv->driver, &driver_attr_adapter);
  1021. driver_remove_file(&drv->driver, &driver_attr_eeprom_cmd);
  1022. driver_remove_file(&drv->driver, &driver_attr_eeprom_data);
  1023. driver_remove_file(&drv->driver, &driver_attr_flash_cmd);
  1024. driver_remove_file(&drv->driver, &driver_attr_flash_data);
  1025. driver_remove_file(&drv->driver, &driver_attr_nonidx_addr);
  1026. driver_remove_file(&drv->driver, &driver_attr_nonidx_data);
  1027. driver_remove_file(&drv->driver, &driver_attr_idx_addr);
  1028. driver_remove_file(&drv->driver, &driver_attr_idx_data);
  1029. driver_remove_file(&drv->driver, &driver_attr_wqm_quanta);
  1030. }
  1031. /**
  1032. * nes_init_module - module initialization entry point
  1033. */
  1034. static int __init nes_init_module(void)
  1035. {
  1036. int retval;
  1037. int retval1;
  1038. retval = nes_cm_start();
  1039. if (retval) {
  1040. printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");
  1041. return retval;
  1042. }
  1043. retval = pci_register_driver(&nes_pci_driver);
  1044. if (retval >= 0) {
  1045. retval1 = nes_create_driver_sysfs(&nes_pci_driver);
  1046. if (retval1 < 0)
  1047. printk(KERN_ERR PFX "Unable to create NetEffect sys files.\n");
  1048. }
  1049. return retval;
  1050. }
  1051. /**
  1052. * nes_exit_module - module unload entry point
  1053. */
  1054. static void __exit nes_exit_module(void)
  1055. {
  1056. nes_cm_stop();
  1057. nes_remove_driver_sysfs(&nes_pci_driver);
  1058. pci_unregister_driver(&nes_pci_driver);
  1059. }
  1060. module_init(nes_init_module);
  1061. module_exit(nes_exit_module);