main.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668
  1. /* main.c - (formerly known as dldwd_cs.c, orinoco_cs.c and orinoco.c)
  2. *
  3. * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
  4. * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
  5. *
  6. * Current maintainers (as of 29 September 2003) are:
  7. * Pavel Roskin <proski AT gnu.org>
  8. * and David Gibson <hermes AT gibson.dropbear.id.au>
  9. *
  10. * (C) Copyright David Gibson, IBM Corporation 2001-2003.
  11. * Copyright (C) 2000 David Gibson, Linuxcare Australia.
  12. * With some help from :
  13. * Copyright (C) 2001 Jean Tourrilhes, HP Labs
  14. * Copyright (C) 2001 Benjamin Herrenschmidt
  15. *
  16. * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
  17. *
  18. * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
  19. * AT fasta.fh-dortmund.de>
  20. * http://www.stud.fh-dortmund.de/~andy/wvlan/
  21. *
  22. * The contents of this file are subject to the Mozilla Public License
  23. * Version 1.1 (the "License"); you may not use this file except in
  24. * compliance with the License. You may obtain a copy of the License
  25. * at http://www.mozilla.org/MPL/
  26. *
  27. * Software distributed under the License is distributed on an "AS IS"
  28. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  29. * the License for the specific language governing rights and
  30. * limitations under the License.
  31. *
  32. * The initial developer of the original code is David A. Hinds
  33. * <dahinds AT users.sourceforge.net>. Portions created by David
  34. * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
  35. * Reserved.
  36. *
  37. * Alternatively, the contents of this file may be used under the
  38. * terms of the GNU General Public License version 2 (the "GPL"), in
  39. * which case the provisions of the GPL are applicable instead of the
  40. * above. If you wish to allow the use of your version of this file
  41. * only under the terms of the GPL and not to allow others to use your
  42. * version of this file under the MPL, indicate your decision by
  43. * deleting the provisions above and replace them with the notice and
  44. * other provisions required by the GPL. If you do not delete the
  45. * provisions above, a recipient may use your version of this file
  46. * under either the MPL or the GPL. */
  47. /*
  48. * TODO
  49. * o Handle de-encapsulation within network layer, provide 802.11
  50. * headers (patch from Thomas 'Dent' Mirlacher)
  51. * o Fix possible races in SPY handling.
  52. * o Disconnect wireless extensions from fundamental configuration.
  53. * o (maybe) Software WEP support (patch from Stano Meduna).
  54. * o (maybe) Use multiple Tx buffers - driver handling queue
  55. * rather than firmware.
  56. */
  57. /* Locking and synchronization:
  58. *
  59. * The basic principle is that everything is serialized through a
  60. * single spinlock, priv->lock. The lock is used in user, bh and irq
  61. * context, so when taken outside hardirq context it should always be
  62. * taken with interrupts disabled. The lock protects both the
  63. * hardware and the struct orinoco_private.
  64. *
  65. * Another flag, priv->hw_unavailable indicates that the hardware is
  66. * unavailable for an extended period of time (e.g. suspended, or in
  67. * the middle of a hard reset). This flag is protected by the
  68. * spinlock. All code which touches the hardware should check the
  69. * flag after taking the lock, and if it is set, give up on whatever
  70. * they are doing and drop the lock again. The orinoco_lock()
  71. * function handles this (it unlocks and returns -EBUSY if
  72. * hw_unavailable is non-zero).
  73. */
  74. #define DRIVER_NAME "orinoco"
  75. #include <linux/module.h>
  76. #include <linux/kernel.h>
  77. #include <linux/init.h>
  78. #include <linux/delay.h>
  79. #include <linux/netdevice.h>
  80. #include <linux/etherdevice.h>
  81. #include <linux/ethtool.h>
  82. #include <linux/suspend.h>
  83. #include <linux/if_arp.h>
  84. #include <linux/wireless.h>
  85. #include <linux/ieee80211.h>
  86. #include <net/iw_handler.h>
  87. #include "hermes_rid.h"
  88. #include "hermes_dld.h"
  89. #include "hw.h"
  90. #include "scan.h"
  91. #include "mic.h"
  92. #include "fw.h"
  93. #include "wext.h"
  94. #include "main.h"
  95. #include "orinoco.h"
  96. /********************************************************************/
  97. /* Module information */
  98. /********************************************************************/
  99. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
  100. "David Gibson <hermes@gibson.dropbear.id.au>");
  101. MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
  102. "and similar wireless cards");
  103. MODULE_LICENSE("Dual MPL/GPL");
  104. /* Level of debugging. Used in the macros in orinoco.h */
  105. #ifdef ORINOCO_DEBUG
  106. int orinoco_debug = ORINOCO_DEBUG;
  107. EXPORT_SYMBOL(orinoco_debug);
  108. module_param(orinoco_debug, int, 0644);
  109. MODULE_PARM_DESC(orinoco_debug, "Debug level");
  110. #endif
  111. static int suppress_linkstatus; /* = 0 */
  112. module_param(suppress_linkstatus, bool, 0644);
  113. MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
  114. static int ignore_disconnect; /* = 0 */
  115. module_param(ignore_disconnect, int, 0644);
  116. MODULE_PARM_DESC(ignore_disconnect,
  117. "Don't report lost link to the network layer");
  118. int force_monitor; /* = 0 */
  119. module_param(force_monitor, int, 0644);
  120. MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
  121. /********************************************************************/
  122. /* Internal constants */
  123. /********************************************************************/
  124. /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
  125. static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
  126. #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
  127. #define ORINOCO_MIN_MTU 256
  128. #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
  129. #define SYMBOL_MAX_VER_LEN (14)
  130. #define MAX_IRQLOOPS_PER_IRQ 10
  131. #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
  132. * how many events the
  133. * device could
  134. * legitimately generate */
  135. #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
  136. #define DUMMY_FID 0xFFFF
  137. /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
  138. HERMES_MAX_MULTICAST : 0)*/
  139. #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
  140. #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
  141. | HERMES_EV_TX | HERMES_EV_TXEXC \
  142. | HERMES_EV_WTERR | HERMES_EV_INFO \
  143. | HERMES_EV_INFDROP)
  144. static const struct ethtool_ops orinoco_ethtool_ops;
  145. /********************************************************************/
  146. /* Data types */
  147. /********************************************************************/
  148. /* Beginning of the Tx descriptor, used in TxExc handling */
  149. struct hermes_txexc_data {
  150. struct hermes_tx_descriptor desc;
  151. __le16 frame_ctl;
  152. __le16 duration_id;
  153. u8 addr1[ETH_ALEN];
  154. } __attribute__ ((packed));
  155. /* Rx frame header except compatibility 802.3 header */
  156. struct hermes_rx_descriptor {
  157. /* Control */
  158. __le16 status;
  159. __le32 time;
  160. u8 silence;
  161. u8 signal;
  162. u8 rate;
  163. u8 rxflow;
  164. __le32 reserved;
  165. /* 802.11 header */
  166. __le16 frame_ctl;
  167. __le16 duration_id;
  168. u8 addr1[ETH_ALEN];
  169. u8 addr2[ETH_ALEN];
  170. u8 addr3[ETH_ALEN];
  171. __le16 seq_ctl;
  172. u8 addr4[ETH_ALEN];
  173. /* Data length */
  174. __le16 data_len;
  175. } __attribute__ ((packed));
  176. struct orinoco_rx_data {
  177. struct hermes_rx_descriptor *desc;
  178. struct sk_buff *skb;
  179. struct list_head list;
  180. };
  181. /********************************************************************/
  182. /* Function prototypes */
  183. /********************************************************************/
  184. static void __orinoco_set_multicast_list(struct net_device *dev);
  185. /********************************************************************/
  186. /* Internal helper functions */
  187. /********************************************************************/
  188. void set_port_type(struct orinoco_private *priv)
  189. {
  190. switch (priv->iw_mode) {
  191. case IW_MODE_INFRA:
  192. priv->port_type = 1;
  193. priv->createibss = 0;
  194. break;
  195. case IW_MODE_ADHOC:
  196. if (priv->prefer_port3) {
  197. priv->port_type = 3;
  198. priv->createibss = 0;
  199. } else {
  200. priv->port_type = priv->ibss_port;
  201. priv->createibss = 1;
  202. }
  203. break;
  204. case IW_MODE_MONITOR:
  205. priv->port_type = 3;
  206. priv->createibss = 0;
  207. break;
  208. default:
  209. printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
  210. priv->ndev->name);
  211. }
  212. }
  213. /********************************************************************/
  214. /* Device methods */
  215. /********************************************************************/
  216. static int orinoco_open(struct net_device *dev)
  217. {
  218. struct orinoco_private *priv = netdev_priv(dev);
  219. unsigned long flags;
  220. int err;
  221. if (orinoco_lock(priv, &flags) != 0)
  222. return -EBUSY;
  223. err = __orinoco_up(dev);
  224. if (!err)
  225. priv->open = 1;
  226. orinoco_unlock(priv, &flags);
  227. return err;
  228. }
  229. static int orinoco_stop(struct net_device *dev)
  230. {
  231. struct orinoco_private *priv = netdev_priv(dev);
  232. int err = 0;
  233. /* We mustn't use orinoco_lock() here, because we need to be
  234. able to close the interface even if hw_unavailable is set
  235. (e.g. as we're released after a PC Card removal) */
  236. spin_lock_irq(&priv->lock);
  237. priv->open = 0;
  238. err = __orinoco_down(dev);
  239. spin_unlock_irq(&priv->lock);
  240. return err;
  241. }
  242. static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
  243. {
  244. struct orinoco_private *priv = netdev_priv(dev);
  245. return &priv->stats;
  246. }
  247. static void orinoco_set_multicast_list(struct net_device *dev)
  248. {
  249. struct orinoco_private *priv = netdev_priv(dev);
  250. unsigned long flags;
  251. if (orinoco_lock(priv, &flags) != 0) {
  252. printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
  253. "called when hw_unavailable\n", dev->name);
  254. return;
  255. }
  256. __orinoco_set_multicast_list(dev);
  257. orinoco_unlock(priv, &flags);
  258. }
  259. static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
  260. {
  261. struct orinoco_private *priv = netdev_priv(dev);
  262. if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
  263. return -EINVAL;
  264. /* MTU + encapsulation + header length */
  265. if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
  266. (priv->nicbuf_size - ETH_HLEN))
  267. return -EINVAL;
  268. dev->mtu = new_mtu;
  269. return 0;
  270. }
  271. /********************************************************************/
  272. /* Tx path */
  273. /********************************************************************/
  274. static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
  275. {
  276. struct orinoco_private *priv = netdev_priv(dev);
  277. struct net_device_stats *stats = &priv->stats;
  278. hermes_t *hw = &priv->hw;
  279. int err = 0;
  280. u16 txfid = priv->txfid;
  281. struct ethhdr *eh;
  282. int tx_control;
  283. unsigned long flags;
  284. if (!netif_running(dev)) {
  285. printk(KERN_ERR "%s: Tx on stopped device!\n",
  286. dev->name);
  287. return NETDEV_TX_BUSY;
  288. }
  289. if (netif_queue_stopped(dev)) {
  290. printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
  291. dev->name);
  292. return NETDEV_TX_BUSY;
  293. }
  294. if (orinoco_lock(priv, &flags) != 0) {
  295. printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
  296. dev->name);
  297. return NETDEV_TX_BUSY;
  298. }
  299. if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
  300. /* Oops, the firmware hasn't established a connection,
  301. silently drop the packet (this seems to be the
  302. safest approach). */
  303. goto drop;
  304. }
  305. /* Check packet length */
  306. if (skb->len < ETH_HLEN)
  307. goto drop;
  308. tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
  309. if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
  310. tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
  311. HERMES_TXCTRL_MIC;
  312. if (priv->has_alt_txcntl) {
  313. /* WPA enabled firmwares have tx_cntl at the end of
  314. * the 802.11 header. So write zeroed descriptor and
  315. * 802.11 header at the same time
  316. */
  317. char desc[HERMES_802_3_OFFSET];
  318. __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
  319. memset(&desc, 0, sizeof(desc));
  320. *txcntl = cpu_to_le16(tx_control);
  321. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
  322. txfid, 0);
  323. if (err) {
  324. if (net_ratelimit())
  325. printk(KERN_ERR "%s: Error %d writing Tx "
  326. "descriptor to BAP\n", dev->name, err);
  327. goto busy;
  328. }
  329. } else {
  330. struct hermes_tx_descriptor desc;
  331. memset(&desc, 0, sizeof(desc));
  332. desc.tx_control = cpu_to_le16(tx_control);
  333. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
  334. txfid, 0);
  335. if (err) {
  336. if (net_ratelimit())
  337. printk(KERN_ERR "%s: Error %d writing Tx "
  338. "descriptor to BAP\n", dev->name, err);
  339. goto busy;
  340. }
  341. /* Clear the 802.11 header and data length fields - some
  342. * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
  343. * if this isn't done. */
  344. hermes_clear_words(hw, HERMES_DATA0,
  345. HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
  346. }
  347. eh = (struct ethhdr *)skb->data;
  348. /* Encapsulate Ethernet-II frames */
  349. if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
  350. struct header_struct {
  351. struct ethhdr eth; /* 802.3 header */
  352. u8 encap[6]; /* 802.2 header */
  353. } __attribute__ ((packed)) hdr;
  354. /* Strip destination and source from the data */
  355. skb_pull(skb, 2 * ETH_ALEN);
  356. /* And move them to a separate header */
  357. memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
  358. hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
  359. memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
  360. /* Insert the SNAP header */
  361. if (skb_headroom(skb) < sizeof(hdr)) {
  362. printk(KERN_ERR
  363. "%s: Not enough headroom for 802.2 headers %d\n",
  364. dev->name, skb_headroom(skb));
  365. goto drop;
  366. }
  367. eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
  368. memcpy(eh, &hdr, sizeof(hdr));
  369. }
  370. err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
  371. txfid, HERMES_802_3_OFFSET);
  372. if (err) {
  373. printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
  374. dev->name, err);
  375. goto busy;
  376. }
  377. /* Calculate Michael MIC */
  378. if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
  379. u8 mic_buf[MICHAEL_MIC_LEN + 1];
  380. u8 *mic;
  381. size_t offset;
  382. size_t len;
  383. if (skb->len % 2) {
  384. /* MIC start is on an odd boundary */
  385. mic_buf[0] = skb->data[skb->len - 1];
  386. mic = &mic_buf[1];
  387. offset = skb->len - 1;
  388. len = MICHAEL_MIC_LEN + 1;
  389. } else {
  390. mic = &mic_buf[0];
  391. offset = skb->len;
  392. len = MICHAEL_MIC_LEN;
  393. }
  394. orinoco_mic(priv->tx_tfm_mic,
  395. priv->tkip_key[priv->tx_key].tx_mic,
  396. eh->h_dest, eh->h_source, 0 /* priority */,
  397. skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
  398. /* Write the MIC */
  399. err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
  400. txfid, HERMES_802_3_OFFSET + offset);
  401. if (err) {
  402. printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
  403. dev->name, err);
  404. goto busy;
  405. }
  406. }
  407. /* Finally, we actually initiate the send */
  408. netif_stop_queue(dev);
  409. err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
  410. txfid, NULL);
  411. if (err) {
  412. netif_start_queue(dev);
  413. if (net_ratelimit())
  414. printk(KERN_ERR "%s: Error %d transmitting packet\n",
  415. dev->name, err);
  416. goto busy;
  417. }
  418. dev->trans_start = jiffies;
  419. stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
  420. goto ok;
  421. drop:
  422. stats->tx_errors++;
  423. stats->tx_dropped++;
  424. ok:
  425. orinoco_unlock(priv, &flags);
  426. dev_kfree_skb(skb);
  427. return NETDEV_TX_OK;
  428. busy:
  429. if (err == -EIO)
  430. schedule_work(&priv->reset_work);
  431. orinoco_unlock(priv, &flags);
  432. return NETDEV_TX_BUSY;
  433. }
  434. static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
  435. {
  436. struct orinoco_private *priv = netdev_priv(dev);
  437. u16 fid = hermes_read_regn(hw, ALLOCFID);
  438. if (fid != priv->txfid) {
  439. if (fid != DUMMY_FID)
  440. printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
  441. dev->name, fid);
  442. return;
  443. }
  444. hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
  445. }
  446. static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
  447. {
  448. struct orinoco_private *priv = netdev_priv(dev);
  449. struct net_device_stats *stats = &priv->stats;
  450. stats->tx_packets++;
  451. netif_wake_queue(dev);
  452. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  453. }
  454. static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
  455. {
  456. struct orinoco_private *priv = netdev_priv(dev);
  457. struct net_device_stats *stats = &priv->stats;
  458. u16 fid = hermes_read_regn(hw, TXCOMPLFID);
  459. u16 status;
  460. struct hermes_txexc_data hdr;
  461. int err = 0;
  462. if (fid == DUMMY_FID)
  463. return; /* Nothing's really happened */
  464. /* Read part of the frame header - we need status and addr1 */
  465. err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
  466. sizeof(struct hermes_txexc_data),
  467. fid, 0);
  468. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  469. stats->tx_errors++;
  470. if (err) {
  471. printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
  472. "(FID=%04X error %d)\n",
  473. dev->name, fid, err);
  474. return;
  475. }
  476. DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
  477. err, fid);
  478. /* We produce a TXDROP event only for retry or lifetime
  479. * exceeded, because that's the only status that really mean
  480. * that this particular node went away.
  481. * Other errors means that *we* screwed up. - Jean II */
  482. status = le16_to_cpu(hdr.desc.status);
  483. if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
  484. union iwreq_data wrqu;
  485. /* Copy 802.11 dest address.
  486. * We use the 802.11 header because the frame may
  487. * not be 802.3 or may be mangled...
  488. * In Ad-Hoc mode, it will be the node address.
  489. * In managed mode, it will be most likely the AP addr
  490. * User space will figure out how to convert it to
  491. * whatever it needs (IP address or else).
  492. * - Jean II */
  493. memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
  494. wrqu.addr.sa_family = ARPHRD_ETHER;
  495. /* Send event to user space */
  496. wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
  497. }
  498. netif_wake_queue(dev);
  499. }
  500. static void orinoco_tx_timeout(struct net_device *dev)
  501. {
  502. struct orinoco_private *priv = netdev_priv(dev);
  503. struct net_device_stats *stats = &priv->stats;
  504. struct hermes *hw = &priv->hw;
  505. printk(KERN_WARNING "%s: Tx timeout! "
  506. "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
  507. dev->name, hermes_read_regn(hw, ALLOCFID),
  508. hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
  509. stats->tx_errors++;
  510. schedule_work(&priv->reset_work);
  511. }
  512. /********************************************************************/
  513. /* Rx path (data frames) */
  514. /********************************************************************/
  515. /* Does the frame have a SNAP header indicating it should be
  516. * de-encapsulated to Ethernet-II? */
  517. static inline int is_ethersnap(void *_hdr)
  518. {
  519. u8 *hdr = _hdr;
  520. /* We de-encapsulate all packets which, a) have SNAP headers
  521. * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
  522. * and where b) the OUI of the SNAP header is 00:00:00 or
  523. * 00:00:f8 - we need both because different APs appear to use
  524. * different OUIs for some reason */
  525. return (memcmp(hdr, &encaps_hdr, 5) == 0)
  526. && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
  527. }
  528. static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
  529. int level, int noise)
  530. {
  531. struct iw_quality wstats;
  532. wstats.level = level - 0x95;
  533. wstats.noise = noise - 0x95;
  534. wstats.qual = (level > noise) ? (level - noise) : 0;
  535. wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  536. /* Update spy records */
  537. wireless_spy_update(dev, mac, &wstats);
  538. }
  539. static void orinoco_stat_gather(struct net_device *dev,
  540. struct sk_buff *skb,
  541. struct hermes_rx_descriptor *desc)
  542. {
  543. struct orinoco_private *priv = netdev_priv(dev);
  544. /* Using spy support with lots of Rx packets, like in an
  545. * infrastructure (AP), will really slow down everything, because
  546. * the MAC address must be compared to each entry of the spy list.
  547. * If the user really asks for it (set some address in the
  548. * spy list), we do it, but he will pay the price.
  549. * Note that to get here, you need both WIRELESS_SPY
  550. * compiled in AND some addresses in the list !!!
  551. */
  552. /* Note : gcc will optimise the whole section away if
  553. * WIRELESS_SPY is not defined... - Jean II */
  554. if (SPY_NUMBER(priv)) {
  555. orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
  556. desc->signal, desc->silence);
  557. }
  558. }
  559. /*
  560. * orinoco_rx_monitor - handle received monitor frames.
  561. *
  562. * Arguments:
  563. * dev network device
  564. * rxfid received FID
  565. * desc rx descriptor of the frame
  566. *
  567. * Call context: interrupt
  568. */
  569. static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
  570. struct hermes_rx_descriptor *desc)
  571. {
  572. u32 hdrlen = 30; /* return full header by default */
  573. u32 datalen = 0;
  574. u16 fc;
  575. int err;
  576. int len;
  577. struct sk_buff *skb;
  578. struct orinoco_private *priv = netdev_priv(dev);
  579. struct net_device_stats *stats = &priv->stats;
  580. hermes_t *hw = &priv->hw;
  581. len = le16_to_cpu(desc->data_len);
  582. /* Determine the size of the header and the data */
  583. fc = le16_to_cpu(desc->frame_ctl);
  584. switch (fc & IEEE80211_FCTL_FTYPE) {
  585. case IEEE80211_FTYPE_DATA:
  586. if ((fc & IEEE80211_FCTL_TODS)
  587. && (fc & IEEE80211_FCTL_FROMDS))
  588. hdrlen = 30;
  589. else
  590. hdrlen = 24;
  591. datalen = len;
  592. break;
  593. case IEEE80211_FTYPE_MGMT:
  594. hdrlen = 24;
  595. datalen = len;
  596. break;
  597. case IEEE80211_FTYPE_CTL:
  598. switch (fc & IEEE80211_FCTL_STYPE) {
  599. case IEEE80211_STYPE_PSPOLL:
  600. case IEEE80211_STYPE_RTS:
  601. case IEEE80211_STYPE_CFEND:
  602. case IEEE80211_STYPE_CFENDACK:
  603. hdrlen = 16;
  604. break;
  605. case IEEE80211_STYPE_CTS:
  606. case IEEE80211_STYPE_ACK:
  607. hdrlen = 10;
  608. break;
  609. }
  610. break;
  611. default:
  612. /* Unknown frame type */
  613. break;
  614. }
  615. /* sanity check the length */
  616. if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
  617. printk(KERN_DEBUG "%s: oversized monitor frame, "
  618. "data length = %d\n", dev->name, datalen);
  619. stats->rx_length_errors++;
  620. goto update_stats;
  621. }
  622. skb = dev_alloc_skb(hdrlen + datalen);
  623. if (!skb) {
  624. printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
  625. dev->name);
  626. goto update_stats;
  627. }
  628. /* Copy the 802.11 header to the skb */
  629. memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
  630. skb_reset_mac_header(skb);
  631. /* If any, copy the data from the card to the skb */
  632. if (datalen > 0) {
  633. err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
  634. ALIGN(datalen, 2), rxfid,
  635. HERMES_802_2_OFFSET);
  636. if (err) {
  637. printk(KERN_ERR "%s: error %d reading monitor frame\n",
  638. dev->name, err);
  639. goto drop;
  640. }
  641. }
  642. skb->dev = dev;
  643. skb->ip_summed = CHECKSUM_NONE;
  644. skb->pkt_type = PACKET_OTHERHOST;
  645. skb->protocol = cpu_to_be16(ETH_P_802_2);
  646. stats->rx_packets++;
  647. stats->rx_bytes += skb->len;
  648. netif_rx(skb);
  649. return;
  650. drop:
  651. dev_kfree_skb_irq(skb);
  652. update_stats:
  653. stats->rx_errors++;
  654. stats->rx_dropped++;
  655. }
  656. static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
  657. {
  658. struct orinoco_private *priv = netdev_priv(dev);
  659. struct net_device_stats *stats = &priv->stats;
  660. struct iw_statistics *wstats = &priv->wstats;
  661. struct sk_buff *skb = NULL;
  662. u16 rxfid, status;
  663. int length;
  664. struct hermes_rx_descriptor *desc;
  665. struct orinoco_rx_data *rx_data;
  666. int err;
  667. desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
  668. if (!desc) {
  669. printk(KERN_WARNING
  670. "%s: Can't allocate space for RX descriptor\n",
  671. dev->name);
  672. goto update_stats;
  673. }
  674. rxfid = hermes_read_regn(hw, RXFID);
  675. err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
  676. rxfid, 0);
  677. if (err) {
  678. printk(KERN_ERR "%s: error %d reading Rx descriptor. "
  679. "Frame dropped.\n", dev->name, err);
  680. goto update_stats;
  681. }
  682. status = le16_to_cpu(desc->status);
  683. if (status & HERMES_RXSTAT_BADCRC) {
  684. DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
  685. dev->name);
  686. stats->rx_crc_errors++;
  687. goto update_stats;
  688. }
  689. /* Handle frames in monitor mode */
  690. if (priv->iw_mode == IW_MODE_MONITOR) {
  691. orinoco_rx_monitor(dev, rxfid, desc);
  692. goto out;
  693. }
  694. if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
  695. DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
  696. dev->name);
  697. wstats->discard.code++;
  698. goto update_stats;
  699. }
  700. length = le16_to_cpu(desc->data_len);
  701. /* Sanity checks */
  702. if (length < 3) { /* No for even an 802.2 LLC header */
  703. /* At least on Symbol firmware with PCF we get quite a
  704. lot of these legitimately - Poll frames with no
  705. data. */
  706. goto out;
  707. }
  708. if (length > IEEE80211_MAX_DATA_LEN) {
  709. printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
  710. dev->name, length);
  711. stats->rx_length_errors++;
  712. goto update_stats;
  713. }
  714. /* Payload size does not include Michael MIC. Increase payload
  715. * size to read it together with the data. */
  716. if (status & HERMES_RXSTAT_MIC)
  717. length += MICHAEL_MIC_LEN;
  718. /* We need space for the packet data itself, plus an ethernet
  719. header, plus 2 bytes so we can align the IP header on a
  720. 32bit boundary, plus 1 byte so we can read in odd length
  721. packets from the card, which has an IO granularity of 16
  722. bits */
  723. skb = dev_alloc_skb(length+ETH_HLEN+2+1);
  724. if (!skb) {
  725. printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
  726. dev->name);
  727. goto update_stats;
  728. }
  729. /* We'll prepend the header, so reserve space for it. The worst
  730. case is no decapsulation, when 802.3 header is prepended and
  731. nothing is removed. 2 is for aligning the IP header. */
  732. skb_reserve(skb, ETH_HLEN + 2);
  733. err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
  734. ALIGN(length, 2), rxfid,
  735. HERMES_802_2_OFFSET);
  736. if (err) {
  737. printk(KERN_ERR "%s: error %d reading frame. "
  738. "Frame dropped.\n", dev->name, err);
  739. goto drop;
  740. }
  741. /* Add desc and skb to rx queue */
  742. rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
  743. if (!rx_data) {
  744. printk(KERN_WARNING "%s: Can't allocate RX packet\n",
  745. dev->name);
  746. goto drop;
  747. }
  748. rx_data->desc = desc;
  749. rx_data->skb = skb;
  750. list_add_tail(&rx_data->list, &priv->rx_list);
  751. tasklet_schedule(&priv->rx_tasklet);
  752. return;
  753. drop:
  754. dev_kfree_skb_irq(skb);
  755. update_stats:
  756. stats->rx_errors++;
  757. stats->rx_dropped++;
  758. out:
  759. kfree(desc);
  760. }
  761. static void orinoco_rx(struct net_device *dev,
  762. struct hermes_rx_descriptor *desc,
  763. struct sk_buff *skb)
  764. {
  765. struct orinoco_private *priv = netdev_priv(dev);
  766. struct net_device_stats *stats = &priv->stats;
  767. u16 status, fc;
  768. int length;
  769. struct ethhdr *hdr;
  770. status = le16_to_cpu(desc->status);
  771. length = le16_to_cpu(desc->data_len);
  772. fc = le16_to_cpu(desc->frame_ctl);
  773. /* Calculate and check MIC */
  774. if (status & HERMES_RXSTAT_MIC) {
  775. int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
  776. HERMES_MIC_KEY_ID_SHIFT);
  777. u8 mic[MICHAEL_MIC_LEN];
  778. u8 *rxmic;
  779. u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
  780. desc->addr3 : desc->addr2;
  781. /* Extract Michael MIC from payload */
  782. rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
  783. skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
  784. length -= MICHAEL_MIC_LEN;
  785. orinoco_mic(priv->rx_tfm_mic,
  786. priv->tkip_key[key_id].rx_mic,
  787. desc->addr1,
  788. src,
  789. 0, /* priority or QoS? */
  790. skb->data,
  791. skb->len,
  792. &mic[0]);
  793. if (memcmp(mic, rxmic,
  794. MICHAEL_MIC_LEN)) {
  795. union iwreq_data wrqu;
  796. struct iw_michaelmicfailure wxmic;
  797. printk(KERN_WARNING "%s: "
  798. "Invalid Michael MIC in data frame from %pM, "
  799. "using key %i\n",
  800. dev->name, src, key_id);
  801. /* TODO: update stats */
  802. /* Notify userspace */
  803. memset(&wxmic, 0, sizeof(wxmic));
  804. wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
  805. wxmic.flags |= (desc->addr1[0] & 1) ?
  806. IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
  807. wxmic.src_addr.sa_family = ARPHRD_ETHER;
  808. memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
  809. (void) orinoco_hw_get_tkip_iv(priv, key_id,
  810. &wxmic.tsc[0]);
  811. memset(&wrqu, 0, sizeof(wrqu));
  812. wrqu.data.length = sizeof(wxmic);
  813. wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
  814. (char *) &wxmic);
  815. goto drop;
  816. }
  817. }
  818. /* Handle decapsulation
  819. * In most cases, the firmware tell us about SNAP frames.
  820. * For some reason, the SNAP frames sent by LinkSys APs
  821. * are not properly recognised by most firmwares.
  822. * So, check ourselves */
  823. if (length >= ENCAPS_OVERHEAD &&
  824. (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
  825. ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
  826. is_ethersnap(skb->data))) {
  827. /* These indicate a SNAP within 802.2 LLC within
  828. 802.11 frame which we'll need to de-encapsulate to
  829. the original EthernetII frame. */
  830. hdr = (struct ethhdr *)skb_push(skb,
  831. ETH_HLEN - ENCAPS_OVERHEAD);
  832. } else {
  833. /* 802.3 frame - prepend 802.3 header as is */
  834. hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
  835. hdr->h_proto = htons(length);
  836. }
  837. memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
  838. if (fc & IEEE80211_FCTL_FROMDS)
  839. memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
  840. else
  841. memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
  842. skb->protocol = eth_type_trans(skb, dev);
  843. skb->ip_summed = CHECKSUM_NONE;
  844. if (fc & IEEE80211_FCTL_TODS)
  845. skb->pkt_type = PACKET_OTHERHOST;
  846. /* Process the wireless stats if needed */
  847. orinoco_stat_gather(dev, skb, desc);
  848. /* Pass the packet to the networking stack */
  849. netif_rx(skb);
  850. stats->rx_packets++;
  851. stats->rx_bytes += length;
  852. return;
  853. drop:
  854. dev_kfree_skb(skb);
  855. stats->rx_errors++;
  856. stats->rx_dropped++;
  857. }
  858. static void orinoco_rx_isr_tasklet(unsigned long data)
  859. {
  860. struct net_device *dev = (struct net_device *) data;
  861. struct orinoco_private *priv = netdev_priv(dev);
  862. struct orinoco_rx_data *rx_data, *temp;
  863. struct hermes_rx_descriptor *desc;
  864. struct sk_buff *skb;
  865. unsigned long flags;
  866. /* orinoco_rx requires the driver lock, and we also need to
  867. * protect priv->rx_list, so just hold the lock over the
  868. * lot.
  869. *
  870. * If orinoco_lock fails, we've unplugged the card. In this
  871. * case just abort. */
  872. if (orinoco_lock(priv, &flags) != 0)
  873. return;
  874. /* extract desc and skb from queue */
  875. list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
  876. desc = rx_data->desc;
  877. skb = rx_data->skb;
  878. list_del(&rx_data->list);
  879. kfree(rx_data);
  880. orinoco_rx(dev, desc, skb);
  881. kfree(desc);
  882. }
  883. orinoco_unlock(priv, &flags);
  884. }
  885. /********************************************************************/
  886. /* Rx path (info frames) */
  887. /********************************************************************/
  888. static void print_linkstatus(struct net_device *dev, u16 status)
  889. {
  890. char *s;
  891. if (suppress_linkstatus)
  892. return;
  893. switch (status) {
  894. case HERMES_LINKSTATUS_NOT_CONNECTED:
  895. s = "Not Connected";
  896. break;
  897. case HERMES_LINKSTATUS_CONNECTED:
  898. s = "Connected";
  899. break;
  900. case HERMES_LINKSTATUS_DISCONNECTED:
  901. s = "Disconnected";
  902. break;
  903. case HERMES_LINKSTATUS_AP_CHANGE:
  904. s = "AP Changed";
  905. break;
  906. case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
  907. s = "AP Out of Range";
  908. break;
  909. case HERMES_LINKSTATUS_AP_IN_RANGE:
  910. s = "AP In Range";
  911. break;
  912. case HERMES_LINKSTATUS_ASSOC_FAILED:
  913. s = "Association Failed";
  914. break;
  915. default:
  916. s = "UNKNOWN";
  917. }
  918. printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
  919. dev->name, s, status);
  920. }
  921. /* Search scan results for requested BSSID, join it if found */
  922. static void orinoco_join_ap(struct work_struct *work)
  923. {
  924. struct orinoco_private *priv =
  925. container_of(work, struct orinoco_private, join_work);
  926. struct net_device *dev = priv->ndev;
  927. struct hermes *hw = &priv->hw;
  928. int err;
  929. unsigned long flags;
  930. struct join_req {
  931. u8 bssid[ETH_ALEN];
  932. __le16 channel;
  933. } __attribute__ ((packed)) req;
  934. const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
  935. struct prism2_scan_apinfo *atom = NULL;
  936. int offset = 4;
  937. int found = 0;
  938. u8 *buf;
  939. u16 len;
  940. /* Allocate buffer for scan results */
  941. buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
  942. if (!buf)
  943. return;
  944. if (orinoco_lock(priv, &flags) != 0)
  945. goto fail_lock;
  946. /* Sanity checks in case user changed something in the meantime */
  947. if (!priv->bssid_fixed)
  948. goto out;
  949. if (strlen(priv->desired_essid) == 0)
  950. goto out;
  951. /* Read scan results from the firmware */
  952. err = hermes_read_ltv(hw, USER_BAP,
  953. HERMES_RID_SCANRESULTSTABLE,
  954. MAX_SCAN_LEN, &len, buf);
  955. if (err) {
  956. printk(KERN_ERR "%s: Cannot read scan results\n",
  957. dev->name);
  958. goto out;
  959. }
  960. len = HERMES_RECLEN_TO_BYTES(len);
  961. /* Go through the scan results looking for the channel of the AP
  962. * we were requested to join */
  963. for (; offset + atom_len <= len; offset += atom_len) {
  964. atom = (struct prism2_scan_apinfo *) (buf + offset);
  965. if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
  966. found = 1;
  967. break;
  968. }
  969. }
  970. if (!found) {
  971. DEBUG(1, "%s: Requested AP not found in scan results\n",
  972. dev->name);
  973. goto out;
  974. }
  975. memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
  976. req.channel = atom->channel; /* both are little-endian */
  977. err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
  978. &req);
  979. if (err)
  980. printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
  981. out:
  982. orinoco_unlock(priv, &flags);
  983. fail_lock:
  984. kfree(buf);
  985. }
  986. /* Send new BSSID to userspace */
  987. static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
  988. {
  989. struct net_device *dev = priv->ndev;
  990. struct hermes *hw = &priv->hw;
  991. union iwreq_data wrqu;
  992. int err;
  993. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  994. ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
  995. if (err != 0)
  996. return;
  997. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  998. /* Send event to user space */
  999. wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
  1000. }
  1001. static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
  1002. {
  1003. struct net_device *dev = priv->ndev;
  1004. struct hermes *hw = &priv->hw;
  1005. union iwreq_data wrqu;
  1006. int err;
  1007. u8 buf[88];
  1008. u8 *ie;
  1009. if (!priv->has_wpa)
  1010. return;
  1011. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
  1012. sizeof(buf), NULL, &buf);
  1013. if (err != 0)
  1014. return;
  1015. ie = orinoco_get_wpa_ie(buf, sizeof(buf));
  1016. if (ie) {
  1017. int rem = sizeof(buf) - (ie - &buf[0]);
  1018. wrqu.data.length = ie[1] + 2;
  1019. if (wrqu.data.length > rem)
  1020. wrqu.data.length = rem;
  1021. if (wrqu.data.length)
  1022. /* Send event to user space */
  1023. wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
  1024. }
  1025. }
  1026. static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
  1027. {
  1028. struct net_device *dev = priv->ndev;
  1029. struct hermes *hw = &priv->hw;
  1030. union iwreq_data wrqu;
  1031. int err;
  1032. u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
  1033. u8 *ie;
  1034. if (!priv->has_wpa)
  1035. return;
  1036. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
  1037. sizeof(buf), NULL, &buf);
  1038. if (err != 0)
  1039. return;
  1040. ie = orinoco_get_wpa_ie(buf, sizeof(buf));
  1041. if (ie) {
  1042. int rem = sizeof(buf) - (ie - &buf[0]);
  1043. wrqu.data.length = ie[1] + 2;
  1044. if (wrqu.data.length > rem)
  1045. wrqu.data.length = rem;
  1046. if (wrqu.data.length)
  1047. /* Send event to user space */
  1048. wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
  1049. }
  1050. }
  1051. static void orinoco_send_wevents(struct work_struct *work)
  1052. {
  1053. struct orinoco_private *priv =
  1054. container_of(work, struct orinoco_private, wevent_work);
  1055. unsigned long flags;
  1056. if (orinoco_lock(priv, &flags) != 0)
  1057. return;
  1058. orinoco_send_assocreqie_wevent(priv);
  1059. orinoco_send_assocrespie_wevent(priv);
  1060. orinoco_send_bssid_wevent(priv);
  1061. orinoco_unlock(priv, &flags);
  1062. }
  1063. static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
  1064. {
  1065. struct orinoco_private *priv = netdev_priv(dev);
  1066. u16 infofid;
  1067. struct {
  1068. __le16 len;
  1069. __le16 type;
  1070. } __attribute__ ((packed)) info;
  1071. int len, type;
  1072. int err;
  1073. /* This is an answer to an INQUIRE command that we did earlier,
  1074. * or an information "event" generated by the card
  1075. * The controller return to us a pseudo frame containing
  1076. * the information in question - Jean II */
  1077. infofid = hermes_read_regn(hw, INFOFID);
  1078. /* Read the info frame header - don't try too hard */
  1079. err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
  1080. infofid, 0);
  1081. if (err) {
  1082. printk(KERN_ERR "%s: error %d reading info frame. "
  1083. "Frame dropped.\n", dev->name, err);
  1084. return;
  1085. }
  1086. len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
  1087. type = le16_to_cpu(info.type);
  1088. switch (type) {
  1089. case HERMES_INQ_TALLIES: {
  1090. struct hermes_tallies_frame tallies;
  1091. struct iw_statistics *wstats = &priv->wstats;
  1092. if (len > sizeof(tallies)) {
  1093. printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
  1094. dev->name, len);
  1095. len = sizeof(tallies);
  1096. }
  1097. err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
  1098. infofid, sizeof(info));
  1099. if (err)
  1100. break;
  1101. /* Increment our various counters */
  1102. /* wstats->discard.nwid - no wrong BSSID stuff */
  1103. wstats->discard.code +=
  1104. le16_to_cpu(tallies.RxWEPUndecryptable);
  1105. if (len == sizeof(tallies))
  1106. wstats->discard.code +=
  1107. le16_to_cpu(tallies.RxDiscards_WEPICVError) +
  1108. le16_to_cpu(tallies.RxDiscards_WEPExcluded);
  1109. wstats->discard.misc +=
  1110. le16_to_cpu(tallies.TxDiscardsWrongSA);
  1111. wstats->discard.fragment +=
  1112. le16_to_cpu(tallies.RxMsgInBadMsgFragments);
  1113. wstats->discard.retries +=
  1114. le16_to_cpu(tallies.TxRetryLimitExceeded);
  1115. /* wstats->miss.beacon - no match */
  1116. }
  1117. break;
  1118. case HERMES_INQ_LINKSTATUS: {
  1119. struct hermes_linkstatus linkstatus;
  1120. u16 newstatus;
  1121. int connected;
  1122. if (priv->iw_mode == IW_MODE_MONITOR)
  1123. break;
  1124. if (len != sizeof(linkstatus)) {
  1125. printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
  1126. dev->name, len);
  1127. break;
  1128. }
  1129. err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
  1130. infofid, sizeof(info));
  1131. if (err)
  1132. break;
  1133. newstatus = le16_to_cpu(linkstatus.linkstatus);
  1134. /* Symbol firmware uses "out of range" to signal that
  1135. * the hostscan frame can be requested. */
  1136. if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
  1137. priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
  1138. priv->has_hostscan && priv->scan_inprogress) {
  1139. hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
  1140. break;
  1141. }
  1142. connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
  1143. || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
  1144. || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
  1145. if (connected)
  1146. netif_carrier_on(dev);
  1147. else if (!ignore_disconnect)
  1148. netif_carrier_off(dev);
  1149. if (newstatus != priv->last_linkstatus) {
  1150. priv->last_linkstatus = newstatus;
  1151. print_linkstatus(dev, newstatus);
  1152. /* The info frame contains only one word which is the
  1153. * status (see hermes.h). The status is pretty boring
  1154. * in itself, that's why we export the new BSSID...
  1155. * Jean II */
  1156. schedule_work(&priv->wevent_work);
  1157. }
  1158. }
  1159. break;
  1160. case HERMES_INQ_SCAN:
  1161. if (!priv->scan_inprogress && priv->bssid_fixed &&
  1162. priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
  1163. schedule_work(&priv->join_work);
  1164. break;
  1165. }
  1166. /* fall through */
  1167. case HERMES_INQ_HOSTSCAN:
  1168. case HERMES_INQ_HOSTSCAN_SYMBOL: {
  1169. /* Result of a scanning. Contains information about
  1170. * cells in the vicinity - Jean II */
  1171. union iwreq_data wrqu;
  1172. unsigned char *buf;
  1173. /* Scan is no longer in progress */
  1174. priv->scan_inprogress = 0;
  1175. /* Sanity check */
  1176. if (len > 4096) {
  1177. printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
  1178. dev->name, len);
  1179. break;
  1180. }
  1181. /* Allocate buffer for results */
  1182. buf = kmalloc(len, GFP_ATOMIC);
  1183. if (buf == NULL)
  1184. /* No memory, so can't printk()... */
  1185. break;
  1186. /* Read scan data */
  1187. err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
  1188. infofid, sizeof(info));
  1189. if (err) {
  1190. kfree(buf);
  1191. break;
  1192. }
  1193. #ifdef ORINOCO_DEBUG
  1194. {
  1195. int i;
  1196. printk(KERN_DEBUG "Scan result [%02X", buf[0]);
  1197. for (i = 1; i < (len * 2); i++)
  1198. printk(":%02X", buf[i]);
  1199. printk("]\n");
  1200. }
  1201. #endif /* ORINOCO_DEBUG */
  1202. if (orinoco_process_scan_results(priv, buf, len) == 0) {
  1203. /* Send an empty event to user space.
  1204. * We don't send the received data on the event because
  1205. * it would require us to do complex transcoding, and
  1206. * we want to minimise the work done in the irq handler
  1207. * Use a request to extract the data - Jean II */
  1208. wrqu.data.length = 0;
  1209. wrqu.data.flags = 0;
  1210. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1211. }
  1212. kfree(buf);
  1213. }
  1214. break;
  1215. case HERMES_INQ_CHANNELINFO:
  1216. {
  1217. struct agere_ext_scan_info *bss;
  1218. if (!priv->scan_inprogress) {
  1219. printk(KERN_DEBUG "%s: Got chaninfo without scan, "
  1220. "len=%d\n", dev->name, len);
  1221. break;
  1222. }
  1223. /* An empty result indicates that the scan is complete */
  1224. if (len == 0) {
  1225. union iwreq_data wrqu;
  1226. /* Scan is no longer in progress */
  1227. priv->scan_inprogress = 0;
  1228. wrqu.data.length = 0;
  1229. wrqu.data.flags = 0;
  1230. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1231. break;
  1232. }
  1233. /* Sanity check */
  1234. else if (len > sizeof(*bss)) {
  1235. printk(KERN_WARNING
  1236. "%s: Ext scan results too large (%d bytes). "
  1237. "Truncating results to %zd bytes.\n",
  1238. dev->name, len, sizeof(*bss));
  1239. len = sizeof(*bss);
  1240. } else if (len < (offsetof(struct agere_ext_scan_info,
  1241. data) + 2)) {
  1242. /* Drop this result now so we don't have to
  1243. * keep checking later */
  1244. printk(KERN_WARNING
  1245. "%s: Ext scan results too short (%d bytes)\n",
  1246. dev->name, len);
  1247. break;
  1248. }
  1249. bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
  1250. if (bss == NULL)
  1251. break;
  1252. /* Read scan data */
  1253. err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
  1254. infofid, sizeof(info));
  1255. if (err) {
  1256. kfree(bss);
  1257. break;
  1258. }
  1259. orinoco_add_ext_scan_result(priv, bss);
  1260. kfree(bss);
  1261. break;
  1262. }
  1263. case HERMES_INQ_SEC_STAT_AGERE:
  1264. /* Security status (Agere specific) */
  1265. /* Ignore this frame for now */
  1266. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  1267. break;
  1268. /* fall through */
  1269. default:
  1270. printk(KERN_DEBUG "%s: Unknown information frame received: "
  1271. "type 0x%04x, length %d\n", dev->name, type, len);
  1272. /* We don't actually do anything about it */
  1273. break;
  1274. }
  1275. }
  1276. static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
  1277. {
  1278. if (net_ratelimit())
  1279. printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
  1280. }
  1281. /********************************************************************/
  1282. /* Internal hardware control routines */
  1283. /********************************************************************/
  1284. int __orinoco_up(struct net_device *dev)
  1285. {
  1286. struct orinoco_private *priv = netdev_priv(dev);
  1287. struct hermes *hw = &priv->hw;
  1288. int err;
  1289. netif_carrier_off(dev); /* just to make sure */
  1290. err = __orinoco_program_rids(dev);
  1291. if (err) {
  1292. printk(KERN_ERR "%s: Error %d configuring card\n",
  1293. dev->name, err);
  1294. return err;
  1295. }
  1296. /* Fire things up again */
  1297. hermes_set_irqmask(hw, ORINOCO_INTEN);
  1298. err = hermes_enable_port(hw, 0);
  1299. if (err) {
  1300. printk(KERN_ERR "%s: Error %d enabling MAC port\n",
  1301. dev->name, err);
  1302. return err;
  1303. }
  1304. netif_start_queue(dev);
  1305. return 0;
  1306. }
  1307. EXPORT_SYMBOL(__orinoco_up);
  1308. int __orinoco_down(struct net_device *dev)
  1309. {
  1310. struct orinoco_private *priv = netdev_priv(dev);
  1311. struct hermes *hw = &priv->hw;
  1312. int err;
  1313. netif_stop_queue(dev);
  1314. if (!priv->hw_unavailable) {
  1315. if (!priv->broken_disableport) {
  1316. err = hermes_disable_port(hw, 0);
  1317. if (err) {
  1318. /* Some firmwares (e.g. Intersil 1.3.x) seem
  1319. * to have problems disabling the port, oh
  1320. * well, too bad. */
  1321. printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
  1322. dev->name, err);
  1323. priv->broken_disableport = 1;
  1324. }
  1325. }
  1326. hermes_set_irqmask(hw, 0);
  1327. hermes_write_regn(hw, EVACK, 0xffff);
  1328. }
  1329. /* firmware will have to reassociate */
  1330. netif_carrier_off(dev);
  1331. priv->last_linkstatus = 0xffff;
  1332. return 0;
  1333. }
  1334. EXPORT_SYMBOL(__orinoco_down);
  1335. static int orinoco_allocate_fid(struct net_device *dev)
  1336. {
  1337. struct orinoco_private *priv = netdev_priv(dev);
  1338. struct hermes *hw = &priv->hw;
  1339. int err;
  1340. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1341. if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
  1342. /* Try workaround for old Symbol firmware bug */
  1343. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  1344. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1345. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  1346. "(old Symbol firmware?). Work around %s\n",
  1347. dev->name, err ? "failed!" : "ok.");
  1348. }
  1349. return err;
  1350. }
  1351. int orinoco_reinit_firmware(struct net_device *dev)
  1352. {
  1353. struct orinoco_private *priv = netdev_priv(dev);
  1354. struct hermes *hw = &priv->hw;
  1355. int err;
  1356. err = hermes_init(hw);
  1357. if (priv->do_fw_download && !err) {
  1358. err = orinoco_download(priv);
  1359. if (err)
  1360. priv->do_fw_download = 0;
  1361. }
  1362. if (!err)
  1363. err = orinoco_allocate_fid(dev);
  1364. return err;
  1365. }
  1366. EXPORT_SYMBOL(orinoco_reinit_firmware);
  1367. int __orinoco_program_rids(struct net_device *dev)
  1368. {
  1369. struct orinoco_private *priv = netdev_priv(dev);
  1370. hermes_t *hw = &priv->hw;
  1371. int err;
  1372. struct hermes_idstring idbuf;
  1373. /* Set the MAC address */
  1374. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  1375. HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
  1376. if (err) {
  1377. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  1378. dev->name, err);
  1379. return err;
  1380. }
  1381. /* Set up the link mode */
  1382. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  1383. priv->port_type);
  1384. if (err) {
  1385. printk(KERN_ERR "%s: Error %d setting port type\n",
  1386. dev->name, err);
  1387. return err;
  1388. }
  1389. /* Set the channel/frequency */
  1390. if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
  1391. err = hermes_write_wordrec(hw, USER_BAP,
  1392. HERMES_RID_CNFOWNCHANNEL,
  1393. priv->channel);
  1394. if (err) {
  1395. printk(KERN_ERR "%s: Error %d setting channel %d\n",
  1396. dev->name, err, priv->channel);
  1397. return err;
  1398. }
  1399. }
  1400. if (priv->has_ibss) {
  1401. u16 createibss;
  1402. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  1403. printk(KERN_WARNING "%s: This firmware requires an "
  1404. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  1405. /* With wvlan_cs, in this case, we would crash.
  1406. * hopefully, this driver will behave better...
  1407. * Jean II */
  1408. createibss = 0;
  1409. } else {
  1410. createibss = priv->createibss;
  1411. }
  1412. err = hermes_write_wordrec(hw, USER_BAP,
  1413. HERMES_RID_CNFCREATEIBSS,
  1414. createibss);
  1415. if (err) {
  1416. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  1417. dev->name, err);
  1418. return err;
  1419. }
  1420. }
  1421. /* Set the desired BSSID */
  1422. err = __orinoco_hw_set_wap(priv);
  1423. if (err) {
  1424. printk(KERN_ERR "%s: Error %d setting AP address\n",
  1425. dev->name, err);
  1426. return err;
  1427. }
  1428. /* Set the desired ESSID */
  1429. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  1430. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  1431. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  1432. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  1433. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1434. &idbuf);
  1435. if (err) {
  1436. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  1437. dev->name, err);
  1438. return err;
  1439. }
  1440. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  1441. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1442. &idbuf);
  1443. if (err) {
  1444. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  1445. dev->name, err);
  1446. return err;
  1447. }
  1448. /* Set the station name */
  1449. idbuf.len = cpu_to_le16(strlen(priv->nick));
  1450. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  1451. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  1452. HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
  1453. &idbuf);
  1454. if (err) {
  1455. printk(KERN_ERR "%s: Error %d setting nickname\n",
  1456. dev->name, err);
  1457. return err;
  1458. }
  1459. /* Set AP density */
  1460. if (priv->has_sensitivity) {
  1461. err = hermes_write_wordrec(hw, USER_BAP,
  1462. HERMES_RID_CNFSYSTEMSCALE,
  1463. priv->ap_density);
  1464. if (err) {
  1465. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  1466. "Disabling sensitivity control\n",
  1467. dev->name, err);
  1468. priv->has_sensitivity = 0;
  1469. }
  1470. }
  1471. /* Set RTS threshold */
  1472. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  1473. priv->rts_thresh);
  1474. if (err) {
  1475. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  1476. dev->name, err);
  1477. return err;
  1478. }
  1479. /* Set fragmentation threshold or MWO robustness */
  1480. if (priv->has_mwo)
  1481. err = hermes_write_wordrec(hw, USER_BAP,
  1482. HERMES_RID_CNFMWOROBUST_AGERE,
  1483. priv->mwo_robust);
  1484. else
  1485. err = hermes_write_wordrec(hw, USER_BAP,
  1486. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  1487. priv->frag_thresh);
  1488. if (err) {
  1489. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  1490. dev->name, err);
  1491. return err;
  1492. }
  1493. /* Set bitrate */
  1494. err = __orinoco_hw_set_bitrate(priv);
  1495. if (err) {
  1496. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  1497. dev->name, err);
  1498. return err;
  1499. }
  1500. /* Set power management */
  1501. if (priv->has_pm) {
  1502. err = hermes_write_wordrec(hw, USER_BAP,
  1503. HERMES_RID_CNFPMENABLED,
  1504. priv->pm_on);
  1505. if (err) {
  1506. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1507. dev->name, err);
  1508. return err;
  1509. }
  1510. err = hermes_write_wordrec(hw, USER_BAP,
  1511. HERMES_RID_CNFMULTICASTRECEIVE,
  1512. priv->pm_mcast);
  1513. if (err) {
  1514. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1515. dev->name, err);
  1516. return err;
  1517. }
  1518. err = hermes_write_wordrec(hw, USER_BAP,
  1519. HERMES_RID_CNFMAXSLEEPDURATION,
  1520. priv->pm_period);
  1521. if (err) {
  1522. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1523. dev->name, err);
  1524. return err;
  1525. }
  1526. err = hermes_write_wordrec(hw, USER_BAP,
  1527. HERMES_RID_CNFPMHOLDOVERDURATION,
  1528. priv->pm_timeout);
  1529. if (err) {
  1530. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1531. dev->name, err);
  1532. return err;
  1533. }
  1534. }
  1535. /* Set preamble - only for Symbol so far... */
  1536. if (priv->has_preamble) {
  1537. err = hermes_write_wordrec(hw, USER_BAP,
  1538. HERMES_RID_CNFPREAMBLE_SYMBOL,
  1539. priv->preamble);
  1540. if (err) {
  1541. printk(KERN_ERR "%s: Error %d setting preamble\n",
  1542. dev->name, err);
  1543. return err;
  1544. }
  1545. }
  1546. /* Set up encryption */
  1547. if (priv->has_wep || priv->has_wpa) {
  1548. err = __orinoco_hw_setup_enc(priv);
  1549. if (err) {
  1550. printk(KERN_ERR "%s: Error %d activating encryption\n",
  1551. dev->name, err);
  1552. return err;
  1553. }
  1554. }
  1555. if (priv->iw_mode == IW_MODE_MONITOR) {
  1556. /* Enable monitor mode */
  1557. dev->type = ARPHRD_IEEE80211;
  1558. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  1559. HERMES_TEST_MONITOR, 0, NULL);
  1560. } else {
  1561. /* Disable monitor mode */
  1562. dev->type = ARPHRD_ETHER;
  1563. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  1564. HERMES_TEST_STOP, 0, NULL);
  1565. }
  1566. if (err)
  1567. return err;
  1568. /* Set promiscuity / multicast*/
  1569. priv->promiscuous = 0;
  1570. priv->mc_count = 0;
  1571. /* FIXME: what about netif_tx_lock */
  1572. __orinoco_set_multicast_list(dev);
  1573. return 0;
  1574. }
  1575. /* FIXME: return int? */
  1576. static void
  1577. __orinoco_set_multicast_list(struct net_device *dev)
  1578. {
  1579. struct orinoco_private *priv = netdev_priv(dev);
  1580. int err = 0;
  1581. int promisc, mc_count;
  1582. /* The Hermes doesn't seem to have an allmulti mode, so we go
  1583. * into promiscuous mode and let the upper levels deal. */
  1584. if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
  1585. (dev->mc_count > MAX_MULTICAST(priv))) {
  1586. promisc = 1;
  1587. mc_count = 0;
  1588. } else {
  1589. promisc = 0;
  1590. mc_count = dev->mc_count;
  1591. }
  1592. err = __orinoco_hw_set_multicast_list(priv, dev->mc_list, mc_count,
  1593. promisc);
  1594. }
  1595. /* This must be called from user context, without locks held - use
  1596. * schedule_work() */
  1597. void orinoco_reset(struct work_struct *work)
  1598. {
  1599. struct orinoco_private *priv =
  1600. container_of(work, struct orinoco_private, reset_work);
  1601. struct net_device *dev = priv->ndev;
  1602. struct hermes *hw = &priv->hw;
  1603. int err;
  1604. unsigned long flags;
  1605. if (orinoco_lock(priv, &flags) != 0)
  1606. /* When the hardware becomes available again, whatever
  1607. * detects that is responsible for re-initializing
  1608. * it. So no need for anything further */
  1609. return;
  1610. netif_stop_queue(dev);
  1611. /* Shut off interrupts. Depending on what state the hardware
  1612. * is in, this might not work, but we'll try anyway */
  1613. hermes_set_irqmask(hw, 0);
  1614. hermes_write_regn(hw, EVACK, 0xffff);
  1615. priv->hw_unavailable++;
  1616. priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
  1617. netif_carrier_off(dev);
  1618. orinoco_unlock(priv, &flags);
  1619. /* Scanning support: Cleanup of driver struct */
  1620. orinoco_clear_scan_results(priv, 0);
  1621. priv->scan_inprogress = 0;
  1622. if (priv->hard_reset) {
  1623. err = (*priv->hard_reset)(priv);
  1624. if (err) {
  1625. printk(KERN_ERR "%s: orinoco_reset: Error %d "
  1626. "performing hard reset\n", dev->name, err);
  1627. goto disable;
  1628. }
  1629. }
  1630. err = orinoco_reinit_firmware(dev);
  1631. if (err) {
  1632. printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
  1633. dev->name, err);
  1634. goto disable;
  1635. }
  1636. /* This has to be called from user context */
  1637. spin_lock_irq(&priv->lock);
  1638. priv->hw_unavailable--;
  1639. /* priv->open or priv->hw_unavailable might have changed while
  1640. * we dropped the lock */
  1641. if (priv->open && (!priv->hw_unavailable)) {
  1642. err = __orinoco_up(dev);
  1643. if (err) {
  1644. printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
  1645. dev->name, err);
  1646. } else
  1647. dev->trans_start = jiffies;
  1648. }
  1649. spin_unlock_irq(&priv->lock);
  1650. return;
  1651. disable:
  1652. hermes_set_irqmask(hw, 0);
  1653. netif_device_detach(dev);
  1654. printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
  1655. }
  1656. /********************************************************************/
  1657. /* Interrupt handler */
  1658. /********************************************************************/
  1659. static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
  1660. {
  1661. printk(KERN_DEBUG "%s: TICK\n", dev->name);
  1662. }
  1663. static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
  1664. {
  1665. /* This seems to happen a fair bit under load, but ignoring it
  1666. seems to work fine...*/
  1667. printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
  1668. dev->name);
  1669. }
  1670. irqreturn_t orinoco_interrupt(int irq, void *dev_id)
  1671. {
  1672. struct net_device *dev = dev_id;
  1673. struct orinoco_private *priv = netdev_priv(dev);
  1674. hermes_t *hw = &priv->hw;
  1675. int count = MAX_IRQLOOPS_PER_IRQ;
  1676. u16 evstat, events;
  1677. /* These are used to detect a runaway interrupt situation.
  1678. *
  1679. * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
  1680. * we panic and shut down the hardware
  1681. */
  1682. /* jiffies value the last time we were called */
  1683. static int last_irq_jiffy; /* = 0 */
  1684. static int loops_this_jiffy; /* = 0 */
  1685. unsigned long flags;
  1686. if (orinoco_lock(priv, &flags) != 0) {
  1687. /* If hw is unavailable - we don't know if the irq was
  1688. * for us or not */
  1689. return IRQ_HANDLED;
  1690. }
  1691. evstat = hermes_read_regn(hw, EVSTAT);
  1692. events = evstat & hw->inten;
  1693. if (!events) {
  1694. orinoco_unlock(priv, &flags);
  1695. return IRQ_NONE;
  1696. }
  1697. if (jiffies != last_irq_jiffy)
  1698. loops_this_jiffy = 0;
  1699. last_irq_jiffy = jiffies;
  1700. while (events && count--) {
  1701. if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
  1702. printk(KERN_WARNING "%s: IRQ handler is looping too "
  1703. "much! Resetting.\n", dev->name);
  1704. /* Disable interrupts for now */
  1705. hermes_set_irqmask(hw, 0);
  1706. schedule_work(&priv->reset_work);
  1707. break;
  1708. }
  1709. /* Check the card hasn't been removed */
  1710. if (!hermes_present(hw)) {
  1711. DEBUG(0, "orinoco_interrupt(): card removed\n");
  1712. break;
  1713. }
  1714. if (events & HERMES_EV_TICK)
  1715. __orinoco_ev_tick(dev, hw);
  1716. if (events & HERMES_EV_WTERR)
  1717. __orinoco_ev_wterr(dev, hw);
  1718. if (events & HERMES_EV_INFDROP)
  1719. __orinoco_ev_infdrop(dev, hw);
  1720. if (events & HERMES_EV_INFO)
  1721. __orinoco_ev_info(dev, hw);
  1722. if (events & HERMES_EV_RX)
  1723. __orinoco_ev_rx(dev, hw);
  1724. if (events & HERMES_EV_TXEXC)
  1725. __orinoco_ev_txexc(dev, hw);
  1726. if (events & HERMES_EV_TX)
  1727. __orinoco_ev_tx(dev, hw);
  1728. if (events & HERMES_EV_ALLOC)
  1729. __orinoco_ev_alloc(dev, hw);
  1730. hermes_write_regn(hw, EVACK, evstat);
  1731. evstat = hermes_read_regn(hw, EVSTAT);
  1732. events = evstat & hw->inten;
  1733. };
  1734. orinoco_unlock(priv, &flags);
  1735. return IRQ_HANDLED;
  1736. }
  1737. EXPORT_SYMBOL(orinoco_interrupt);
  1738. /********************************************************************/
  1739. /* Power management */
  1740. /********************************************************************/
  1741. #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
  1742. static int orinoco_pm_notifier(struct notifier_block *notifier,
  1743. unsigned long pm_event,
  1744. void *unused)
  1745. {
  1746. struct orinoco_private *priv = container_of(notifier,
  1747. struct orinoco_private,
  1748. pm_notifier);
  1749. /* All we need to do is cache the firmware before suspend, and
  1750. * release it when we come out.
  1751. *
  1752. * Only need to do this if we're downloading firmware. */
  1753. if (!priv->do_fw_download)
  1754. return NOTIFY_DONE;
  1755. switch (pm_event) {
  1756. case PM_HIBERNATION_PREPARE:
  1757. case PM_SUSPEND_PREPARE:
  1758. orinoco_cache_fw(priv, 0);
  1759. break;
  1760. case PM_POST_RESTORE:
  1761. /* Restore from hibernation failed. We need to clean
  1762. * up in exactly the same way, so fall through. */
  1763. case PM_POST_HIBERNATION:
  1764. case PM_POST_SUSPEND:
  1765. orinoco_uncache_fw(priv);
  1766. break;
  1767. case PM_RESTORE_PREPARE:
  1768. default:
  1769. break;
  1770. }
  1771. return NOTIFY_DONE;
  1772. }
  1773. static void orinoco_register_pm_notifier(struct orinoco_private *priv)
  1774. {
  1775. priv->pm_notifier.notifier_call = orinoco_pm_notifier;
  1776. register_pm_notifier(&priv->pm_notifier);
  1777. }
  1778. static void orinoco_unregister_pm_notifier(struct orinoco_private *priv)
  1779. {
  1780. unregister_pm_notifier(&priv->pm_notifier);
  1781. }
  1782. #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
  1783. #define orinoco_register_pm_notifier(priv) do { } while(0)
  1784. #define orinoco_unregister_pm_notifier(priv) do { } while(0)
  1785. #endif
  1786. /********************************************************************/
  1787. /* Initialization */
  1788. /********************************************************************/
  1789. struct comp_id {
  1790. u16 id, variant, major, minor;
  1791. } __attribute__ ((packed));
  1792. static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
  1793. {
  1794. if (nic_id->id < 0x8000)
  1795. return FIRMWARE_TYPE_AGERE;
  1796. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  1797. return FIRMWARE_TYPE_SYMBOL;
  1798. else
  1799. return FIRMWARE_TYPE_INTERSIL;
  1800. }
  1801. /* Set priv->firmware type, determine firmware properties */
  1802. static int determine_firmware(struct net_device *dev)
  1803. {
  1804. struct orinoco_private *priv = netdev_priv(dev);
  1805. hermes_t *hw = &priv->hw;
  1806. int err;
  1807. struct comp_id nic_id, sta_id;
  1808. unsigned int firmver;
  1809. char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
  1810. /* Get the hardware version */
  1811. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  1812. if (err) {
  1813. printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
  1814. dev->name, err);
  1815. return err;
  1816. }
  1817. le16_to_cpus(&nic_id.id);
  1818. le16_to_cpus(&nic_id.variant);
  1819. le16_to_cpus(&nic_id.major);
  1820. le16_to_cpus(&nic_id.minor);
  1821. printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
  1822. dev->name, nic_id.id, nic_id.variant,
  1823. nic_id.major, nic_id.minor);
  1824. priv->firmware_type = determine_firmware_type(&nic_id);
  1825. /* Get the firmware version */
  1826. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  1827. if (err) {
  1828. printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
  1829. dev->name, err);
  1830. return err;
  1831. }
  1832. le16_to_cpus(&sta_id.id);
  1833. le16_to_cpus(&sta_id.variant);
  1834. le16_to_cpus(&sta_id.major);
  1835. le16_to_cpus(&sta_id.minor);
  1836. printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
  1837. dev->name, sta_id.id, sta_id.variant,
  1838. sta_id.major, sta_id.minor);
  1839. switch (sta_id.id) {
  1840. case 0x15:
  1841. printk(KERN_ERR "%s: Primary firmware is active\n",
  1842. dev->name);
  1843. return -ENODEV;
  1844. case 0x14b:
  1845. printk(KERN_ERR "%s: Tertiary firmware is active\n",
  1846. dev->name);
  1847. return -ENODEV;
  1848. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  1849. case 0x21: /* Symbol Spectrum24 Trilogy */
  1850. break;
  1851. default:
  1852. printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
  1853. dev->name);
  1854. break;
  1855. }
  1856. /* Default capabilities */
  1857. priv->has_sensitivity = 1;
  1858. priv->has_mwo = 0;
  1859. priv->has_preamble = 0;
  1860. priv->has_port3 = 1;
  1861. priv->has_ibss = 1;
  1862. priv->has_wep = 0;
  1863. priv->has_big_wep = 0;
  1864. priv->has_alt_txcntl = 0;
  1865. priv->has_ext_scan = 0;
  1866. priv->has_wpa = 0;
  1867. priv->do_fw_download = 0;
  1868. /* Determine capabilities from the firmware version */
  1869. switch (priv->firmware_type) {
  1870. case FIRMWARE_TYPE_AGERE:
  1871. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  1872. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  1873. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1874. "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
  1875. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  1876. priv->has_ibss = (firmver >= 0x60006);
  1877. priv->has_wep = (firmver >= 0x40020);
  1878. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  1879. Gold cards from the others? */
  1880. priv->has_mwo = (firmver >= 0x60000);
  1881. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  1882. priv->ibss_port = 1;
  1883. priv->has_hostscan = (firmver >= 0x8000a);
  1884. priv->do_fw_download = 1;
  1885. priv->broken_monitor = (firmver >= 0x80000);
  1886. priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
  1887. priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
  1888. priv->has_wpa = (firmver >= 0x9002a);
  1889. /* Tested with Agere firmware :
  1890. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  1891. * Tested CableTron firmware : 4.32 => Anton */
  1892. break;
  1893. case FIRMWARE_TYPE_SYMBOL:
  1894. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  1895. /* Intel MAC : 00:02:B3:* */
  1896. /* 3Com MAC : 00:50:DA:* */
  1897. memset(tmp, 0, sizeof(tmp));
  1898. /* Get the Symbol firmware version */
  1899. err = hermes_read_ltv(hw, USER_BAP,
  1900. HERMES_RID_SECONDARYVERSION_SYMBOL,
  1901. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  1902. if (err) {
  1903. printk(KERN_WARNING
  1904. "%s: Error %d reading Symbol firmware info. "
  1905. "Wildly guessing capabilities...\n",
  1906. dev->name, err);
  1907. firmver = 0;
  1908. tmp[0] = '\0';
  1909. } else {
  1910. /* The firmware revision is a string, the format is
  1911. * something like : "V2.20-01".
  1912. * Quick and dirty parsing... - Jean II
  1913. */
  1914. firmver = ((tmp[1] - '0') << 16)
  1915. | ((tmp[3] - '0') << 12)
  1916. | ((tmp[4] - '0') << 8)
  1917. | ((tmp[6] - '0') << 4)
  1918. | (tmp[7] - '0');
  1919. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  1920. }
  1921. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1922. "Symbol %s", tmp);
  1923. priv->has_ibss = (firmver >= 0x20000);
  1924. priv->has_wep = (firmver >= 0x15012);
  1925. priv->has_big_wep = (firmver >= 0x20000);
  1926. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  1927. (firmver >= 0x29000 && firmver < 0x30000) ||
  1928. firmver >= 0x31000;
  1929. priv->has_preamble = (firmver >= 0x20000);
  1930. priv->ibss_port = 4;
  1931. /* Symbol firmware is found on various cards, but
  1932. * there has been no attempt to check firmware
  1933. * download on non-spectrum_cs based cards.
  1934. *
  1935. * Given that the Agere firmware download works
  1936. * differently, we should avoid doing a firmware
  1937. * download with the Symbol algorithm on non-spectrum
  1938. * cards.
  1939. *
  1940. * For now we can identify a spectrum_cs based card
  1941. * because it has a firmware reset function.
  1942. */
  1943. priv->do_fw_download = (priv->stop_fw != NULL);
  1944. priv->broken_disableport = (firmver == 0x25013) ||
  1945. (firmver >= 0x30000 && firmver <= 0x31000);
  1946. priv->has_hostscan = (firmver >= 0x31001) ||
  1947. (firmver >= 0x29057 && firmver < 0x30000);
  1948. /* Tested with Intel firmware : 0x20015 => Jean II */
  1949. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  1950. break;
  1951. case FIRMWARE_TYPE_INTERSIL:
  1952. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  1953. * Samsung, Compaq 100/200 and Proxim are slightly
  1954. * different and less well tested */
  1955. /* D-Link MAC : 00:40:05:* */
  1956. /* Addtron MAC : 00:90:D1:* */
  1957. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1958. "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
  1959. sta_id.variant);
  1960. firmver = ((unsigned long)sta_id.major << 16) |
  1961. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  1962. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  1963. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  1964. priv->has_pm = (firmver >= 0x000700);
  1965. priv->has_hostscan = (firmver >= 0x010301);
  1966. if (firmver >= 0x000800)
  1967. priv->ibss_port = 0;
  1968. else {
  1969. printk(KERN_NOTICE "%s: Intersil firmware earlier "
  1970. "than v0.8.x - several features not supported\n",
  1971. dev->name);
  1972. priv->ibss_port = 1;
  1973. }
  1974. break;
  1975. }
  1976. printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
  1977. priv->fw_name);
  1978. return 0;
  1979. }
  1980. static int orinoco_init(struct net_device *dev)
  1981. {
  1982. struct orinoco_private *priv = netdev_priv(dev);
  1983. hermes_t *hw = &priv->hw;
  1984. int err = 0;
  1985. struct hermes_idstring nickbuf;
  1986. u16 reclen;
  1987. int len;
  1988. /* No need to lock, the hw_unavailable flag is already set in
  1989. * alloc_orinocodev() */
  1990. priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
  1991. /* Initialize the firmware */
  1992. err = hermes_init(hw);
  1993. if (err != 0) {
  1994. printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
  1995. dev->name, err);
  1996. goto out;
  1997. }
  1998. err = determine_firmware(dev);
  1999. if (err != 0) {
  2000. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2001. dev->name);
  2002. goto out;
  2003. }
  2004. if (priv->do_fw_download) {
  2005. #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
  2006. orinoco_cache_fw(priv, 0);
  2007. #endif
  2008. err = orinoco_download(priv);
  2009. if (err)
  2010. priv->do_fw_download = 0;
  2011. /* Check firmware version again */
  2012. err = determine_firmware(dev);
  2013. if (err != 0) {
  2014. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2015. dev->name);
  2016. goto out;
  2017. }
  2018. }
  2019. if (priv->has_port3)
  2020. printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n",
  2021. dev->name);
  2022. if (priv->has_ibss)
  2023. printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
  2024. dev->name);
  2025. if (priv->has_wep) {
  2026. printk(KERN_DEBUG "%s: WEP supported, %s-bit key\n", dev->name,
  2027. priv->has_big_wep ? "104" : "40");
  2028. }
  2029. if (priv->has_wpa) {
  2030. printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
  2031. if (orinoco_mic_init(priv)) {
  2032. printk(KERN_ERR "%s: Failed to setup MIC crypto "
  2033. "algorithm. Disabling WPA support\n", dev->name);
  2034. priv->has_wpa = 0;
  2035. }
  2036. }
  2037. /* Now we have the firmware capabilities, allocate appropiate
  2038. * sized scan buffers */
  2039. if (orinoco_bss_data_allocate(priv))
  2040. goto out;
  2041. orinoco_bss_data_init(priv);
  2042. /* Get the MAC address */
  2043. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  2044. ETH_ALEN, NULL, dev->dev_addr);
  2045. if (err) {
  2046. printk(KERN_WARNING "%s: failed to read MAC address!\n",
  2047. dev->name);
  2048. goto out;
  2049. }
  2050. printk(KERN_DEBUG "%s: MAC address %pM\n",
  2051. dev->name, dev->dev_addr);
  2052. /* Get the station name */
  2053. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2054. sizeof(nickbuf), &reclen, &nickbuf);
  2055. if (err) {
  2056. printk(KERN_ERR "%s: failed to read station name\n",
  2057. dev->name);
  2058. goto out;
  2059. }
  2060. if (nickbuf.len)
  2061. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  2062. else
  2063. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  2064. memcpy(priv->nick, &nickbuf.val, len);
  2065. priv->nick[len] = '\0';
  2066. printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
  2067. err = orinoco_allocate_fid(dev);
  2068. if (err) {
  2069. printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
  2070. dev->name);
  2071. goto out;
  2072. }
  2073. /* Get allowed channels */
  2074. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  2075. &priv->channel_mask);
  2076. if (err) {
  2077. printk(KERN_ERR "%s: failed to read channel list!\n",
  2078. dev->name);
  2079. goto out;
  2080. }
  2081. /* Get initial AP density */
  2082. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  2083. &priv->ap_density);
  2084. if (err || priv->ap_density < 1 || priv->ap_density > 3)
  2085. priv->has_sensitivity = 0;
  2086. /* Get initial RTS threshold */
  2087. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2088. &priv->rts_thresh);
  2089. if (err) {
  2090. printk(KERN_ERR "%s: failed to read RTS threshold!\n",
  2091. dev->name);
  2092. goto out;
  2093. }
  2094. /* Get initial fragmentation settings */
  2095. if (priv->has_mwo)
  2096. err = hermes_read_wordrec(hw, USER_BAP,
  2097. HERMES_RID_CNFMWOROBUST_AGERE,
  2098. &priv->mwo_robust);
  2099. else
  2100. err = hermes_read_wordrec(hw, USER_BAP,
  2101. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2102. &priv->frag_thresh);
  2103. if (err) {
  2104. printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
  2105. dev->name);
  2106. goto out;
  2107. }
  2108. /* Power management setup */
  2109. if (priv->has_pm) {
  2110. priv->pm_on = 0;
  2111. priv->pm_mcast = 1;
  2112. err = hermes_read_wordrec(hw, USER_BAP,
  2113. HERMES_RID_CNFMAXSLEEPDURATION,
  2114. &priv->pm_period);
  2115. if (err) {
  2116. printk(KERN_ERR "%s: failed to read power management period!\n",
  2117. dev->name);
  2118. goto out;
  2119. }
  2120. err = hermes_read_wordrec(hw, USER_BAP,
  2121. HERMES_RID_CNFPMHOLDOVERDURATION,
  2122. &priv->pm_timeout);
  2123. if (err) {
  2124. printk(KERN_ERR "%s: failed to read power management timeout!\n",
  2125. dev->name);
  2126. goto out;
  2127. }
  2128. }
  2129. /* Preamble setup */
  2130. if (priv->has_preamble) {
  2131. err = hermes_read_wordrec(hw, USER_BAP,
  2132. HERMES_RID_CNFPREAMBLE_SYMBOL,
  2133. &priv->preamble);
  2134. if (err)
  2135. goto out;
  2136. }
  2137. /* Set up the default configuration */
  2138. priv->iw_mode = IW_MODE_INFRA;
  2139. /* By default use IEEE/IBSS ad-hoc mode if we have it */
  2140. priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
  2141. set_port_type(priv);
  2142. priv->channel = 0; /* use firmware default */
  2143. priv->promiscuous = 0;
  2144. priv->encode_alg = IW_ENCODE_ALG_NONE;
  2145. priv->tx_key = 0;
  2146. priv->wpa_enabled = 0;
  2147. priv->tkip_cm_active = 0;
  2148. priv->key_mgmt = 0;
  2149. priv->wpa_ie_len = 0;
  2150. priv->wpa_ie = NULL;
  2151. /* Make the hardware available, as long as it hasn't been
  2152. * removed elsewhere (e.g. by PCMCIA hot unplug) */
  2153. spin_lock_irq(&priv->lock);
  2154. priv->hw_unavailable--;
  2155. spin_unlock_irq(&priv->lock);
  2156. printk(KERN_DEBUG "%s: ready\n", dev->name);
  2157. out:
  2158. return err;
  2159. }
  2160. static const struct net_device_ops orinoco_netdev_ops = {
  2161. .ndo_init = orinoco_init,
  2162. .ndo_open = orinoco_open,
  2163. .ndo_stop = orinoco_stop,
  2164. .ndo_start_xmit = orinoco_xmit,
  2165. .ndo_set_multicast_list = orinoco_set_multicast_list,
  2166. .ndo_change_mtu = orinoco_change_mtu,
  2167. .ndo_set_mac_address = eth_mac_addr,
  2168. .ndo_validate_addr = eth_validate_addr,
  2169. .ndo_tx_timeout = orinoco_tx_timeout,
  2170. .ndo_get_stats = orinoco_get_stats,
  2171. };
  2172. struct net_device
  2173. *alloc_orinocodev(int sizeof_card,
  2174. struct device *device,
  2175. int (*hard_reset)(struct orinoco_private *),
  2176. int (*stop_fw)(struct orinoco_private *, int))
  2177. {
  2178. struct net_device *dev;
  2179. struct orinoco_private *priv;
  2180. dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
  2181. if (!dev)
  2182. return NULL;
  2183. priv = netdev_priv(dev);
  2184. priv->ndev = dev;
  2185. if (sizeof_card)
  2186. priv->card = (void *)((unsigned long)priv
  2187. + sizeof(struct orinoco_private));
  2188. else
  2189. priv->card = NULL;
  2190. priv->dev = device;
  2191. /* Setup / override net_device fields */
  2192. dev->netdev_ops = &orinoco_netdev_ops;
  2193. dev->watchdog_timeo = HZ; /* 1 second timeout */
  2194. dev->ethtool_ops = &orinoco_ethtool_ops;
  2195. dev->wireless_handlers = &orinoco_handler_def;
  2196. #ifdef WIRELESS_SPY
  2197. priv->wireless_data.spy_data = &priv->spy_data;
  2198. dev->wireless_data = &priv->wireless_data;
  2199. #endif
  2200. /* Reserve space in skb for the SNAP header */
  2201. dev->hard_header_len += ENCAPS_OVERHEAD;
  2202. /* Set up default callbacks */
  2203. priv->hard_reset = hard_reset;
  2204. priv->stop_fw = stop_fw;
  2205. spin_lock_init(&priv->lock);
  2206. priv->open = 0;
  2207. priv->hw_unavailable = 1; /* orinoco_init() must clear this
  2208. * before anything else touches the
  2209. * hardware */
  2210. INIT_WORK(&priv->reset_work, orinoco_reset);
  2211. INIT_WORK(&priv->join_work, orinoco_join_ap);
  2212. INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
  2213. INIT_LIST_HEAD(&priv->rx_list);
  2214. tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
  2215. (unsigned long) dev);
  2216. netif_carrier_off(dev);
  2217. priv->last_linkstatus = 0xffff;
  2218. #if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
  2219. priv->cached_pri_fw = NULL;
  2220. priv->cached_fw = NULL;
  2221. #endif
  2222. /* Register PM notifiers */
  2223. orinoco_register_pm_notifier(priv);
  2224. return dev;
  2225. }
  2226. EXPORT_SYMBOL(alloc_orinocodev);
  2227. void free_orinocodev(struct net_device *dev)
  2228. {
  2229. struct orinoco_private *priv = netdev_priv(dev);
  2230. struct orinoco_rx_data *rx_data, *temp;
  2231. /* If the tasklet is scheduled when we call tasklet_kill it
  2232. * will run one final time. However the tasklet will only
  2233. * drain priv->rx_list if the hw is still available. */
  2234. tasklet_kill(&priv->rx_tasklet);
  2235. /* Explicitly drain priv->rx_list */
  2236. list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
  2237. list_del(&rx_data->list);
  2238. dev_kfree_skb(rx_data->skb);
  2239. kfree(rx_data->desc);
  2240. kfree(rx_data);
  2241. }
  2242. orinoco_unregister_pm_notifier(priv);
  2243. orinoco_uncache_fw(priv);
  2244. priv->wpa_ie_len = 0;
  2245. kfree(priv->wpa_ie);
  2246. orinoco_mic_free(priv);
  2247. orinoco_bss_data_free(priv);
  2248. free_netdev(dev);
  2249. }
  2250. EXPORT_SYMBOL(free_orinocodev);
  2251. static void orinoco_get_drvinfo(struct net_device *dev,
  2252. struct ethtool_drvinfo *info)
  2253. {
  2254. struct orinoco_private *priv = netdev_priv(dev);
  2255. strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
  2256. strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
  2257. strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
  2258. if (dev->dev.parent)
  2259. strncpy(info->bus_info, dev_name(dev->dev.parent),
  2260. sizeof(info->bus_info) - 1);
  2261. else
  2262. snprintf(info->bus_info, sizeof(info->bus_info) - 1,
  2263. "PCMCIA %p", priv->hw.iobase);
  2264. }
  2265. static const struct ethtool_ops orinoco_ethtool_ops = {
  2266. .get_drvinfo = orinoco_get_drvinfo,
  2267. .get_link = ethtool_op_get_link,
  2268. };
  2269. /********************************************************************/
  2270. /* Module initialization */
  2271. /********************************************************************/
  2272. /* Can't be declared "const" or the whole __initdata section will
  2273. * become const */
  2274. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  2275. " (David Gibson <hermes@gibson.dropbear.id.au>, "
  2276. "Pavel Roskin <proski@gnu.org>, et al)";
  2277. static int __init init_orinoco(void)
  2278. {
  2279. printk(KERN_DEBUG "%s\n", version);
  2280. return 0;
  2281. }
  2282. static void __exit exit_orinoco(void)
  2283. {
  2284. }
  2285. module_init(init_orinoco);
  2286. module_exit(exit_orinoco);