qeth.h 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. #ifndef __QETH_H__
  2. #define __QETH_H__
  3. #include <linux/if.h>
  4. #include <linux/if_arp.h>
  5. #include <linux/if_tr.h>
  6. #include <linux/trdevice.h>
  7. #include <linux/etherdevice.h>
  8. #include <linux/if_vlan.h>
  9. #include <net/ipv6.h>
  10. #include <linux/in6.h>
  11. #include <net/if_inet6.h>
  12. #include <net/addrconf.h>
  13. #include <linux/bitops.h>
  14. #include <asm/debug.h>
  15. #include <asm/qdio.h>
  16. #include <asm/ccwdev.h>
  17. #include <asm/ccwgroup.h>
  18. #include "qeth_mpc.h"
  19. #define VERSION_QETH_H "$Revision: 1.139 $"
  20. #ifdef CONFIG_QETH_IPV6
  21. #define QETH_VERSION_IPV6 ":IPv6"
  22. #else
  23. #define QETH_VERSION_IPV6 ""
  24. #endif
  25. #ifdef CONFIG_QETH_VLAN
  26. #define QETH_VERSION_VLAN ":VLAN"
  27. #else
  28. #define QETH_VERSION_VLAN ""
  29. #endif
  30. /**
  31. * Debug Facility stuff
  32. */
  33. #define QETH_DBF_SETUP_NAME "qeth_setup"
  34. #define QETH_DBF_SETUP_LEN 8
  35. #define QETH_DBF_SETUP_PAGES 8
  36. #define QETH_DBF_SETUP_NR_AREAS 1
  37. #define QETH_DBF_SETUP_LEVEL 5
  38. #define QETH_DBF_MISC_NAME "qeth_misc"
  39. #define QETH_DBF_MISC_LEN 128
  40. #define QETH_DBF_MISC_PAGES 2
  41. #define QETH_DBF_MISC_NR_AREAS 1
  42. #define QETH_DBF_MISC_LEVEL 2
  43. #define QETH_DBF_DATA_NAME "qeth_data"
  44. #define QETH_DBF_DATA_LEN 96
  45. #define QETH_DBF_DATA_PAGES 8
  46. #define QETH_DBF_DATA_NR_AREAS 1
  47. #define QETH_DBF_DATA_LEVEL 2
  48. #define QETH_DBF_CONTROL_NAME "qeth_control"
  49. #define QETH_DBF_CONTROL_LEN 256
  50. #define QETH_DBF_CONTROL_PAGES 8
  51. #define QETH_DBF_CONTROL_NR_AREAS 2
  52. #define QETH_DBF_CONTROL_LEVEL 5
  53. #define QETH_DBF_TRACE_NAME "qeth_trace"
  54. #define QETH_DBF_TRACE_LEN 8
  55. #define QETH_DBF_TRACE_PAGES 4
  56. #define QETH_DBF_TRACE_NR_AREAS 2
  57. #define QETH_DBF_TRACE_LEVEL 3
  58. extern debug_info_t *qeth_dbf_trace;
  59. #define QETH_DBF_SENSE_NAME "qeth_sense"
  60. #define QETH_DBF_SENSE_LEN 64
  61. #define QETH_DBF_SENSE_PAGES 2
  62. #define QETH_DBF_SENSE_NR_AREAS 1
  63. #define QETH_DBF_SENSE_LEVEL 2
  64. #define QETH_DBF_QERR_NAME "qeth_qerr"
  65. #define QETH_DBF_QERR_LEN 8
  66. #define QETH_DBF_QERR_PAGES 2
  67. #define QETH_DBF_QERR_NR_AREAS 2
  68. #define QETH_DBF_QERR_LEVEL 2
  69. #define QETH_DBF_TEXT(name,level,text) \
  70. do { \
  71. debug_text_event(qeth_dbf_##name,level,text); \
  72. } while (0)
  73. #define QETH_DBF_HEX(name,level,addr,len) \
  74. do { \
  75. debug_event(qeth_dbf_##name,level,(void*)(addr),len); \
  76. } while (0)
  77. DECLARE_PER_CPU(char[256], qeth_dbf_txt_buf);
  78. #define QETH_DBF_TEXT_(name,level,text...) \
  79. do { \
  80. char* dbf_txt_buf = get_cpu_var(qeth_dbf_txt_buf); \
  81. sprintf(dbf_txt_buf, text); \
  82. debug_text_event(qeth_dbf_##name,level,dbf_txt_buf); \
  83. put_cpu_var(qeth_dbf_txt_buf); \
  84. } while (0)
  85. #define QETH_DBF_SPRINTF(name,level,text...) \
  86. do { \
  87. debug_sprintf_event(qeth_dbf_trace, level, ##text ); \
  88. debug_sprintf_event(qeth_dbf_trace, level, text ); \
  89. } while (0)
  90. /**
  91. * some more debug stuff
  92. */
  93. #define PRINTK_HEADER "qeth: "
  94. #define HEXDUMP16(importance,header,ptr) \
  95. PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \
  96. "%02x %02x %02x %02x %02x %02x %02x %02x\n", \
  97. *(((char*)ptr)),*(((char*)ptr)+1),*(((char*)ptr)+2), \
  98. *(((char*)ptr)+3),*(((char*)ptr)+4),*(((char*)ptr)+5), \
  99. *(((char*)ptr)+6),*(((char*)ptr)+7),*(((char*)ptr)+8), \
  100. *(((char*)ptr)+9),*(((char*)ptr)+10),*(((char*)ptr)+11), \
  101. *(((char*)ptr)+12),*(((char*)ptr)+13), \
  102. *(((char*)ptr)+14),*(((char*)ptr)+15)); \
  103. PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \
  104. "%02x %02x %02x %02x %02x %02x %02x %02x\n", \
  105. *(((char*)ptr)+16),*(((char*)ptr)+17), \
  106. *(((char*)ptr)+18),*(((char*)ptr)+19), \
  107. *(((char*)ptr)+20),*(((char*)ptr)+21), \
  108. *(((char*)ptr)+22),*(((char*)ptr)+23), \
  109. *(((char*)ptr)+24),*(((char*)ptr)+25), \
  110. *(((char*)ptr)+26),*(((char*)ptr)+27), \
  111. *(((char*)ptr)+28),*(((char*)ptr)+29), \
  112. *(((char*)ptr)+30),*(((char*)ptr)+31));
  113. static inline void
  114. qeth_hex_dump(unsigned char *buf, size_t len)
  115. {
  116. size_t i;
  117. for (i = 0; i < len; i++) {
  118. if (i && !(i % 16))
  119. printk("\n");
  120. printk("%02x ", *(buf + i));
  121. }
  122. printk("\n");
  123. }
  124. #define SENSE_COMMAND_REJECT_BYTE 0
  125. #define SENSE_COMMAND_REJECT_FLAG 0x80
  126. #define SENSE_RESETTING_EVENT_BYTE 1
  127. #define SENSE_RESETTING_EVENT_FLAG 0x80
  128. #define atomic_swap(a,b) xchg((int *)a.counter, b)
  129. /*
  130. * Common IO related definitions
  131. */
  132. extern struct device *qeth_root_dev;
  133. extern struct ccw_driver qeth_ccw_driver;
  134. extern struct ccwgroup_driver qeth_ccwgroup_driver;
  135. #define CARD_RDEV(card) card->read.ccwdev
  136. #define CARD_WDEV(card) card->write.ccwdev
  137. #define CARD_DDEV(card) card->data.ccwdev
  138. #define CARD_BUS_ID(card) card->gdev->dev.bus_id
  139. #define CARD_RDEV_ID(card) card->read.ccwdev->dev.bus_id
  140. #define CARD_WDEV_ID(card) card->write.ccwdev->dev.bus_id
  141. #define CARD_DDEV_ID(card) card->data.ccwdev->dev.bus_id
  142. #define CHANNEL_ID(channel) channel->ccwdev->dev.bus_id
  143. #define CARD_FROM_CDEV(cdev) (struct qeth_card *) \
  144. ((struct ccwgroup_device *)cdev->dev.driver_data)\
  145. ->dev.driver_data;
  146. /**
  147. * card stuff
  148. */
  149. #ifdef CONFIG_QETH_PERF_STATS
  150. struct qeth_perf_stats {
  151. unsigned int bufs_rec;
  152. unsigned int bufs_sent;
  153. unsigned int skbs_sent_pack;
  154. unsigned int bufs_sent_pack;
  155. unsigned int sc_dp_p;
  156. unsigned int sc_p_dp;
  157. /* qdio_input_handler: number of times called, time spent in */
  158. __u64 inbound_start_time;
  159. unsigned int inbound_cnt;
  160. unsigned int inbound_time;
  161. /* qeth_send_packet: number of times called, time spent in */
  162. __u64 outbound_start_time;
  163. unsigned int outbound_cnt;
  164. unsigned int outbound_time;
  165. /* qdio_output_handler: number of times called, time spent in */
  166. __u64 outbound_handler_start_time;
  167. unsigned int outbound_handler_cnt;
  168. unsigned int outbound_handler_time;
  169. /* number of calls to and time spent in do_QDIO for inbound queue */
  170. __u64 inbound_do_qdio_start_time;
  171. unsigned int inbound_do_qdio_cnt;
  172. unsigned int inbound_do_qdio_time;
  173. /* number of calls to and time spent in do_QDIO for outbound queues */
  174. __u64 outbound_do_qdio_start_time;
  175. unsigned int outbound_do_qdio_cnt;
  176. unsigned int outbound_do_qdio_time;
  177. /* eddp data */
  178. unsigned int large_send_bytes;
  179. unsigned int large_send_cnt;
  180. unsigned int sg_skbs_sent;
  181. unsigned int sg_frags_sent;
  182. };
  183. #endif /* CONFIG_QETH_PERF_STATS */
  184. /* Routing stuff */
  185. struct qeth_routing_info {
  186. enum qeth_routing_types type;
  187. };
  188. /* IPA stuff */
  189. struct qeth_ipa_info {
  190. __u32 supported_funcs;
  191. __u32 enabled_funcs;
  192. };
  193. static inline int
  194. qeth_is_ipa_supported(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
  195. {
  196. return (ipa->supported_funcs & func);
  197. }
  198. static inline int
  199. qeth_is_ipa_enabled(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
  200. {
  201. return (ipa->supported_funcs & ipa->enabled_funcs & func);
  202. }
  203. #define qeth_adp_supported(c,f) \
  204. qeth_is_ipa_supported(&c->options.adp, f)
  205. #define qeth_adp_enabled(c,f) \
  206. qeth_is_ipa_enabled(&c->options.adp, f)
  207. #define qeth_is_supported(c,f) \
  208. qeth_is_ipa_supported(&c->options.ipa4, f)
  209. #define qeth_is_enabled(c,f) \
  210. qeth_is_ipa_enabled(&c->options.ipa4, f)
  211. #ifdef CONFIG_QETH_IPV6
  212. #define qeth_is_supported6(c,f) \
  213. qeth_is_ipa_supported(&c->options.ipa6, f)
  214. #define qeth_is_enabled6(c,f) \
  215. qeth_is_ipa_enabled(&c->options.ipa6, f)
  216. #else /* CONFIG_QETH_IPV6 */
  217. #define qeth_is_supported6(c,f) 0
  218. #define qeth_is_enabled6(c,f) 0
  219. #endif /* CONFIG_QETH_IPV6 */
  220. #define qeth_is_ipafunc_supported(c,prot,f) \
  221. (prot==QETH_PROT_IPV6)? qeth_is_supported6(c,f):qeth_is_supported(c,f)
  222. #define qeth_is_ipafunc_enabled(c,prot,f) \
  223. (prot==QETH_PROT_IPV6)? qeth_is_enabled6(c,f):qeth_is_enabled(c,f)
  224. #define QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT 0x0101
  225. #define QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT 0x0101
  226. #define QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT 0x4108
  227. #define QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT 0x5108
  228. #define QETH_MODELLIST_ARRAY \
  229. {{0x1731,0x01,0x1732,0x01,QETH_CARD_TYPE_OSAE,1, \
  230. QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT, \
  231. QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT, \
  232. QETH_MAX_QUEUES,0}, \
  233. {0x1731,0x05,0x1732,0x05,QETH_CARD_TYPE_IQD,0, \
  234. QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT, \
  235. QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT, \
  236. QETH_MAX_QUEUES,0x103}, \
  237. {0,0,0,0,0,0,0,0,0}}
  238. #define QETH_REAL_CARD 1
  239. #define QETH_VLAN_CARD 2
  240. #define QETH_BUFSIZE 4096
  241. /**
  242. * some more defs
  243. */
  244. #define IF_NAME_LEN 16
  245. #define QETH_TX_TIMEOUT 100 * HZ
  246. #define QETH_HEADER_SIZE 32
  247. #define MAX_PORTNO 15
  248. #define QETH_FAKE_LL_LEN_ETH ETH_HLEN
  249. #define QETH_FAKE_LL_LEN_TR (sizeof(struct trh_hdr)-TR_MAXRIFLEN+sizeof(struct trllc))
  250. #define QETH_FAKE_LL_V6_ADDR_POS 24
  251. /*IPv6 address autoconfiguration stuff*/
  252. #define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
  253. #define UNIQUE_ID_NOT_BY_CARD 0x10000
  254. /*****************************************************************************/
  255. /* QDIO queue and buffer handling */
  256. /*****************************************************************************/
  257. #define QETH_MAX_QUEUES 4
  258. #define QETH_IN_BUF_SIZE_DEFAULT 65536
  259. #define QETH_IN_BUF_COUNT_DEFAULT 16
  260. #define QETH_IN_BUF_COUNT_MIN 8
  261. #define QETH_IN_BUF_COUNT_MAX 128
  262. #define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
  263. #define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
  264. ((card)->qdio.in_buf_pool.buf_count / 2)
  265. /* buffers we have to be behind before we get a PCI */
  266. #define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
  267. /*enqueued free buffers left before we get a PCI*/
  268. #define QETH_PCI_THRESHOLD_B(card) 0
  269. /*not used unless the microcode gets patched*/
  270. #define QETH_PCI_TIMER_VALUE(card) 3
  271. #define QETH_MIN_INPUT_THRESHOLD 1
  272. #define QETH_MAX_INPUT_THRESHOLD 500
  273. #define QETH_MIN_OUTPUT_THRESHOLD 1
  274. #define QETH_MAX_OUTPUT_THRESHOLD 300
  275. /* priority queing */
  276. #define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
  277. #define QETH_DEFAULT_QUEUE 2
  278. #define QETH_NO_PRIO_QUEUEING 0
  279. #define QETH_PRIO_Q_ING_PREC 1
  280. #define QETH_PRIO_Q_ING_TOS 2
  281. #define IP_TOS_LOWDELAY 0x10
  282. #define IP_TOS_HIGHTHROUGHPUT 0x08
  283. #define IP_TOS_HIGHRELIABILITY 0x04
  284. #define IP_TOS_NOTIMPORTANT 0x02
  285. /* Packing */
  286. #define QETH_LOW_WATERMARK_PACK 2
  287. #define QETH_HIGH_WATERMARK_PACK 5
  288. #define QETH_WATERMARK_PACK_FUZZ 1
  289. #define QETH_IP_HEADER_SIZE 40
  290. struct qeth_hdr_layer3 {
  291. __u8 id;
  292. __u8 flags;
  293. __u16 inbound_checksum; /*TSO:__u16 seqno */
  294. __u32 token; /*TSO: __u32 reserved */
  295. __u16 length;
  296. __u8 vlan_prio;
  297. __u8 ext_flags;
  298. __u16 vlan_id;
  299. __u16 frame_offset;
  300. __u8 dest_addr[16];
  301. } __attribute__ ((packed));
  302. struct qeth_hdr_layer2 {
  303. __u8 id;
  304. __u8 flags[3];
  305. __u8 port_no;
  306. __u8 hdr_length;
  307. __u16 pkt_length;
  308. __u16 seq_no;
  309. __u16 vlan_id;
  310. __u32 reserved;
  311. __u8 reserved2[16];
  312. } __attribute__ ((packed));
  313. struct qeth_hdr {
  314. union {
  315. struct qeth_hdr_layer2 l2;
  316. struct qeth_hdr_layer3 l3;
  317. } hdr;
  318. } __attribute__ ((packed));
  319. /*TCP Segmentation Offload header*/
  320. struct qeth_hdr_ext_tso {
  321. __u16 hdr_tot_len;
  322. __u8 imb_hdr_no;
  323. __u8 reserved;
  324. __u8 hdr_type;
  325. __u8 hdr_version;
  326. __u16 hdr_len;
  327. __u32 payload_len;
  328. __u16 mss;
  329. __u16 dg_hdr_len;
  330. __u8 padding[16];
  331. } __attribute__ ((packed));
  332. struct qeth_hdr_tso {
  333. struct qeth_hdr hdr; /*hdr->hdr.l3.xxx*/
  334. struct qeth_hdr_ext_tso ext;
  335. } __attribute__ ((packed));
  336. /* flags for qeth_hdr.flags */
  337. #define QETH_HDR_PASSTHRU 0x10
  338. #define QETH_HDR_IPV6 0x80
  339. #define QETH_HDR_CAST_MASK 0x07
  340. enum qeth_cast_flags {
  341. QETH_CAST_UNICAST = 0x06,
  342. QETH_CAST_MULTICAST = 0x04,
  343. QETH_CAST_BROADCAST = 0x05,
  344. QETH_CAST_ANYCAST = 0x07,
  345. QETH_CAST_NOCAST = 0x00,
  346. };
  347. enum qeth_layer2_frame_flags {
  348. QETH_LAYER2_FLAG_MULTICAST = 0x01,
  349. QETH_LAYER2_FLAG_BROADCAST = 0x02,
  350. QETH_LAYER2_FLAG_UNICAST = 0x04,
  351. QETH_LAYER2_FLAG_VLAN = 0x10,
  352. };
  353. enum qeth_header_ids {
  354. QETH_HEADER_TYPE_LAYER3 = 0x01,
  355. QETH_HEADER_TYPE_LAYER2 = 0x02,
  356. QETH_HEADER_TYPE_TSO = 0x03,
  357. };
  358. /* flags for qeth_hdr.ext_flags */
  359. #define QETH_HDR_EXT_VLAN_FRAME 0x01
  360. #define QETH_HDR_EXT_TOKEN_ID 0x02
  361. #define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
  362. #define QETH_HDR_EXT_SRC_MAC_ADDR 0x08
  363. #define QETH_HDR_EXT_CSUM_HDR_REQ 0x10
  364. #define QETH_HDR_EXT_CSUM_TRANSP_REQ 0x20
  365. #define QETH_HDR_EXT_UDP_TSO 0x40 /*bit off for TCP*/
  366. static inline int
  367. qeth_is_last_sbale(struct qdio_buffer_element *sbale)
  368. {
  369. return (sbale->flags & SBAL_FLAGS_LAST_ENTRY);
  370. }
  371. enum qeth_qdio_buffer_states {
  372. /*
  373. * inbound: read out by driver; owned by hardware in order to be filled
  374. * outbound: owned by driver in order to be filled
  375. */
  376. QETH_QDIO_BUF_EMPTY,
  377. /*
  378. * inbound: filled by hardware; owned by driver in order to be read out
  379. * outbound: filled by driver; owned by hardware in order to be sent
  380. */
  381. QETH_QDIO_BUF_PRIMED,
  382. };
  383. enum qeth_qdio_info_states {
  384. QETH_QDIO_UNINITIALIZED,
  385. QETH_QDIO_ALLOCATED,
  386. QETH_QDIO_ESTABLISHED,
  387. };
  388. struct qeth_buffer_pool_entry {
  389. struct list_head list;
  390. struct list_head init_list;
  391. void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
  392. };
  393. struct qeth_qdio_buffer_pool {
  394. struct list_head entry_list;
  395. int buf_count;
  396. };
  397. struct qeth_qdio_buffer {
  398. struct qdio_buffer *buffer;
  399. volatile enum qeth_qdio_buffer_states state;
  400. /* the buffer pool entry currently associated to this buffer */
  401. struct qeth_buffer_pool_entry *pool_entry;
  402. };
  403. struct qeth_qdio_q {
  404. struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
  405. struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
  406. /*
  407. * buf_to_init means "buffer must be initialized by driver and must
  408. * be made available for hardware" -> state is set to EMPTY
  409. */
  410. volatile int next_buf_to_init;
  411. } __attribute__ ((aligned(256)));
  412. /* possible types of qeth large_send support */
  413. enum qeth_large_send_types {
  414. QETH_LARGE_SEND_NO,
  415. QETH_LARGE_SEND_EDDP,
  416. QETH_LARGE_SEND_TSO,
  417. };
  418. struct qeth_qdio_out_buffer {
  419. struct qdio_buffer *buffer;
  420. atomic_t state;
  421. volatile int next_element_to_fill;
  422. struct sk_buff_head skb_list;
  423. struct list_head ctx_list;
  424. };
  425. struct qeth_card;
  426. enum qeth_out_q_states {
  427. QETH_OUT_Q_UNLOCKED,
  428. QETH_OUT_Q_LOCKED,
  429. QETH_OUT_Q_LOCKED_FLUSH,
  430. };
  431. struct qeth_qdio_out_q {
  432. struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
  433. struct qeth_qdio_out_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
  434. int queue_no;
  435. struct qeth_card *card;
  436. atomic_t state;
  437. volatile int do_pack;
  438. /*
  439. * index of buffer to be filled by driver; state EMPTY or PACKING
  440. */
  441. volatile int next_buf_to_fill;
  442. /*
  443. * number of buffers that are currently filled (PRIMED)
  444. * -> these buffers are hardware-owned
  445. */
  446. atomic_t used_buffers;
  447. /* indicates whether PCI flag must be set (or if one is outstanding) */
  448. atomic_t set_pci_flags_count;
  449. } __attribute__ ((aligned(256)));
  450. struct qeth_qdio_info {
  451. volatile enum qeth_qdio_info_states state;
  452. /* input */
  453. struct qeth_qdio_q *in_q;
  454. struct qeth_qdio_buffer_pool in_buf_pool;
  455. struct qeth_qdio_buffer_pool init_pool;
  456. int in_buf_size;
  457. /* output */
  458. int no_out_queues;
  459. struct qeth_qdio_out_q **out_qs;
  460. /* priority queueing */
  461. int do_prio_queueing;
  462. int default_out_queue;
  463. };
  464. enum qeth_send_errors {
  465. QETH_SEND_ERROR_NONE,
  466. QETH_SEND_ERROR_LINK_FAILURE,
  467. QETH_SEND_ERROR_RETRY,
  468. QETH_SEND_ERROR_KICK_IT,
  469. };
  470. #define QETH_ETH_MAC_V4 0x0100 /* like v4 */
  471. #define QETH_ETH_MAC_V6 0x3333 /* like v6 */
  472. /* tr mc mac is longer, but that will be enough to detect mc frames */
  473. #define QETH_TR_MAC_NC 0xc000 /* non-canonical */
  474. #define QETH_TR_MAC_C 0x0300 /* canonical */
  475. #define DEFAULT_ADD_HHLEN 0
  476. #define MAX_ADD_HHLEN 1024
  477. /**
  478. * buffer stuff for read channel
  479. */
  480. #define QETH_CMD_BUFFER_NO 8
  481. /**
  482. * channel state machine
  483. */
  484. enum qeth_channel_states {
  485. CH_STATE_UP,
  486. CH_STATE_DOWN,
  487. CH_STATE_ACTIVATING,
  488. CH_STATE_HALTED,
  489. CH_STATE_STOPPED,
  490. };
  491. /**
  492. * card state machine
  493. */
  494. enum qeth_card_states {
  495. CARD_STATE_DOWN,
  496. CARD_STATE_HARDSETUP,
  497. CARD_STATE_SOFTSETUP,
  498. CARD_STATE_UP,
  499. CARD_STATE_RECOVER,
  500. };
  501. /**
  502. * Protocol versions
  503. */
  504. enum qeth_prot_versions {
  505. QETH_PROT_SNA = 0x0001,
  506. QETH_PROT_IPV4 = 0x0004,
  507. QETH_PROT_IPV6 = 0x0006,
  508. };
  509. enum qeth_ip_types {
  510. QETH_IP_TYPE_NORMAL,
  511. QETH_IP_TYPE_VIPA,
  512. QETH_IP_TYPE_RXIP,
  513. QETH_IP_TYPE_DEL_ALL_MC,
  514. };
  515. enum qeth_cmd_buffer_state {
  516. BUF_STATE_FREE,
  517. BUF_STATE_LOCKED,
  518. BUF_STATE_PROCESSED,
  519. };
  520. /**
  521. * IP address and multicast list
  522. */
  523. struct qeth_ipaddr {
  524. struct list_head entry;
  525. enum qeth_ip_types type;
  526. enum qeth_ipa_setdelip_flags set_flags;
  527. enum qeth_ipa_setdelip_flags del_flags;
  528. int is_multicast;
  529. volatile int users;
  530. enum qeth_prot_versions proto;
  531. unsigned char mac[OSA_ADDR_LEN];
  532. union {
  533. struct {
  534. unsigned int addr;
  535. unsigned int mask;
  536. } a4;
  537. struct {
  538. struct in6_addr addr;
  539. unsigned int pfxlen;
  540. } a6;
  541. } u;
  542. };
  543. struct qeth_ipato_entry {
  544. struct list_head entry;
  545. enum qeth_prot_versions proto;
  546. char addr[16];
  547. int mask_bits;
  548. };
  549. struct qeth_ipato {
  550. int enabled;
  551. int invert4;
  552. int invert6;
  553. struct list_head entries;
  554. };
  555. struct qeth_channel;
  556. struct qeth_cmd_buffer {
  557. enum qeth_cmd_buffer_state state;
  558. struct qeth_channel *channel;
  559. unsigned char *data;
  560. int rc;
  561. void (*callback) (struct qeth_channel *, struct qeth_cmd_buffer *);
  562. };
  563. /**
  564. * definition of a qeth channel, used for read and write
  565. */
  566. struct qeth_channel {
  567. enum qeth_channel_states state;
  568. struct ccw1 ccw;
  569. spinlock_t iob_lock;
  570. wait_queue_head_t wait_q;
  571. struct tasklet_struct irq_tasklet;
  572. struct ccw_device *ccwdev;
  573. /*command buffer for control data*/
  574. struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO];
  575. atomic_t irq_pending;
  576. volatile int io_buf_no;
  577. volatile int buf_no;
  578. };
  579. /**
  580. * OSA card related definitions
  581. */
  582. struct qeth_token {
  583. __u32 issuer_rm_w;
  584. __u32 issuer_rm_r;
  585. __u32 cm_filter_w;
  586. __u32 cm_filter_r;
  587. __u32 cm_connection_w;
  588. __u32 cm_connection_r;
  589. __u32 ulp_filter_w;
  590. __u32 ulp_filter_r;
  591. __u32 ulp_connection_w;
  592. __u32 ulp_connection_r;
  593. };
  594. struct qeth_seqno {
  595. __u32 trans_hdr;
  596. __u32 pdu_hdr;
  597. __u32 pdu_hdr_ack;
  598. __u16 ipa;
  599. };
  600. struct qeth_reply {
  601. struct list_head list;
  602. wait_queue_head_t wait_q;
  603. int (*callback)(struct qeth_card *,struct qeth_reply *,unsigned long);
  604. u32 seqno;
  605. unsigned long offset;
  606. int received;
  607. int rc;
  608. void *param;
  609. struct qeth_card *card;
  610. atomic_t refcnt;
  611. };
  612. #define QETH_BROADCAST_WITH_ECHO 1
  613. #define QETH_BROADCAST_WITHOUT_ECHO 2
  614. struct qeth_card_blkt {
  615. int time_total;
  616. int inter_packet;
  617. int inter_packet_jumbo;
  618. };
  619. struct qeth_card_info {
  620. unsigned short unit_addr2;
  621. unsigned short cula;
  622. unsigned short chpid;
  623. __u16 func_level;
  624. char mcl_level[QETH_MCL_LENGTH + 1];
  625. int guestlan;
  626. int layer2_mac_registered;
  627. int portname_required;
  628. int portno;
  629. char portname[9];
  630. enum qeth_card_types type;
  631. enum qeth_link_types link_type;
  632. int is_multicast_different;
  633. int initial_mtu;
  634. int max_mtu;
  635. int broadcast_capable;
  636. int unique_id;
  637. struct qeth_card_blkt blkt;
  638. __u32 csum_mask;
  639. };
  640. struct qeth_card_options {
  641. struct qeth_routing_info route4;
  642. struct qeth_ipa_info ipa4;
  643. struct qeth_ipa_info adp; /*Adapter parameters*/
  644. #ifdef CONFIG_QETH_IPV6
  645. struct qeth_routing_info route6;
  646. struct qeth_ipa_info ipa6;
  647. #endif /* QETH_IPV6 */
  648. enum qeth_checksum_types checksum_type;
  649. int broadcast_mode;
  650. int macaddr_mode;
  651. int fake_broadcast;
  652. int add_hhlen;
  653. int fake_ll;
  654. int layer2;
  655. enum qeth_large_send_types large_send;
  656. };
  657. /*
  658. * thread bits for qeth_card thread masks
  659. */
  660. enum qeth_threads {
  661. QETH_SET_IP_THREAD = 1,
  662. QETH_RECOVER_THREAD = 2,
  663. };
  664. struct qeth_card {
  665. struct list_head list;
  666. enum qeth_card_states state;
  667. int lan_online;
  668. spinlock_t lock;
  669. /*hardware and sysfs stuff*/
  670. struct ccwgroup_device *gdev;
  671. struct qeth_channel read;
  672. struct qeth_channel write;
  673. struct qeth_channel data;
  674. struct net_device *dev;
  675. struct net_device_stats stats;
  676. struct qeth_card_info info;
  677. struct qeth_token token;
  678. struct qeth_seqno seqno;
  679. struct qeth_card_options options;
  680. wait_queue_head_t wait_q;
  681. #ifdef CONFIG_QETH_VLAN
  682. spinlock_t vlanlock;
  683. struct vlan_group *vlangrp;
  684. #endif
  685. struct work_struct kernel_thread_starter;
  686. spinlock_t thread_mask_lock;
  687. volatile unsigned long thread_start_mask;
  688. volatile unsigned long thread_allowed_mask;
  689. volatile unsigned long thread_running_mask;
  690. spinlock_t ip_lock;
  691. struct list_head ip_list;
  692. struct list_head *ip_tbd_list;
  693. struct qeth_ipato ipato;
  694. struct list_head cmd_waiter_list;
  695. /* QDIO buffer handling */
  696. struct qeth_qdio_info qdio;
  697. #ifdef CONFIG_QETH_PERF_STATS
  698. struct qeth_perf_stats perf_stats;
  699. #endif /* CONFIG_QETH_PERF_STATS */
  700. int use_hard_stop;
  701. int (*orig_hard_header)(struct sk_buff *,struct net_device *,
  702. unsigned short,void *,void *,unsigned);
  703. };
  704. struct qeth_card_list_struct {
  705. struct list_head list;
  706. rwlock_t rwlock;
  707. };
  708. extern struct qeth_card_list_struct qeth_card_list;
  709. /*notifier list */
  710. struct qeth_notify_list_struct {
  711. struct list_head list;
  712. struct task_struct *task;
  713. int signum;
  714. };
  715. extern spinlock_t qeth_notify_lock;
  716. extern struct list_head qeth_notify_list;
  717. /*some helper functions*/
  718. #define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
  719. static inline __u8
  720. qeth_get_ipa_adp_type(enum qeth_link_types link_type)
  721. {
  722. switch (link_type) {
  723. case QETH_LINK_TYPE_HSTR:
  724. return 2;
  725. default:
  726. return 1;
  727. }
  728. }
  729. static inline int
  730. qeth_realloc_headroom(struct qeth_card *card, struct sk_buff **skb, int size)
  731. {
  732. struct sk_buff *new_skb = NULL;
  733. if (skb_headroom(*skb) < size){
  734. new_skb = skb_realloc_headroom(*skb, size);
  735. if (!new_skb) {
  736. PRINT_ERR("qeth_prepare_skb: could "
  737. "not realloc headroom for qeth_hdr "
  738. "on interface %s", QETH_CARD_IFNAME(card));
  739. return -ENOMEM;
  740. }
  741. *skb = new_skb;
  742. }
  743. return 0;
  744. }
  745. static inline struct sk_buff *
  746. qeth_pskb_unshare(struct sk_buff *skb, int pri)
  747. {
  748. struct sk_buff *nskb;
  749. if (!skb_cloned(skb))
  750. return skb;
  751. nskb = skb_copy(skb, pri);
  752. kfree_skb(skb); /* free our shared copy */
  753. return nskb;
  754. }
  755. static inline void *
  756. qeth_push_skb(struct qeth_card *card, struct sk_buff **skb, int size)
  757. {
  758. void *hdr;
  759. hdr = (void *) skb_push(*skb, size);
  760. /*
  761. * sanity check, the Linux memory allocation scheme should
  762. * never present us cases like this one (the qdio header size plus
  763. * the first 40 bytes of the paket cross a 4k boundary)
  764. */
  765. if ((((unsigned long) hdr) & (~(PAGE_SIZE - 1))) !=
  766. (((unsigned long) hdr + size +
  767. QETH_IP_HEADER_SIZE) & (~(PAGE_SIZE - 1)))) {
  768. PRINT_ERR("qeth_prepare_skb: misaligned "
  769. "packet on interface %s. Discarded.",
  770. QETH_CARD_IFNAME(card));
  771. return NULL;
  772. }
  773. return hdr;
  774. }
  775. static inline int
  776. qeth_get_hlen(__u8 link_type)
  777. {
  778. #ifdef CONFIG_QETH_IPV6
  779. switch (link_type) {
  780. case QETH_LINK_TYPE_HSTR:
  781. case QETH_LINK_TYPE_LANE_TR:
  782. return sizeof(struct qeth_hdr_tso) + TR_HLEN;
  783. default:
  784. #ifdef CONFIG_QETH_VLAN
  785. return sizeof(struct qeth_hdr_tso) + VLAN_ETH_HLEN;
  786. #else
  787. return sizeof(struct qeth_hdr_tso) + ETH_HLEN;
  788. #endif
  789. }
  790. #else /* CONFIG_QETH_IPV6 */
  791. #ifdef CONFIG_QETH_VLAN
  792. return sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
  793. #else
  794. return sizeof(struct qeth_hdr_tso);
  795. #endif
  796. #endif /* CONFIG_QETH_IPV6 */
  797. }
  798. static inline unsigned short
  799. qeth_get_netdev_flags(struct qeth_card *card)
  800. {
  801. if (card->options.layer2)
  802. return 0;
  803. switch (card->info.type) {
  804. case QETH_CARD_TYPE_IQD:
  805. return IFF_NOARP;
  806. #ifdef CONFIG_QETH_IPV6
  807. default:
  808. return 0;
  809. #else
  810. default:
  811. return IFF_NOARP;
  812. #endif
  813. }
  814. }
  815. static inline int
  816. qeth_get_initial_mtu_for_card(struct qeth_card * card)
  817. {
  818. switch (card->info.type) {
  819. case QETH_CARD_TYPE_UNKNOWN:
  820. return 1500;
  821. case QETH_CARD_TYPE_IQD:
  822. return card->info.max_mtu;
  823. case QETH_CARD_TYPE_OSAE:
  824. switch (card->info.link_type) {
  825. case QETH_LINK_TYPE_HSTR:
  826. case QETH_LINK_TYPE_LANE_TR:
  827. return 2000;
  828. default:
  829. return 1492;
  830. }
  831. default:
  832. return 1500;
  833. }
  834. }
  835. static inline int
  836. qeth_get_max_mtu_for_card(int cardtype)
  837. {
  838. switch (cardtype) {
  839. case QETH_CARD_TYPE_UNKNOWN:
  840. return 61440;
  841. case QETH_CARD_TYPE_OSAE:
  842. return 61440;
  843. case QETH_CARD_TYPE_IQD:
  844. return 57344;
  845. default:
  846. return 1500;
  847. }
  848. }
  849. static inline int
  850. qeth_get_mtu_out_of_mpc(int cardtype)
  851. {
  852. switch (cardtype) {
  853. case QETH_CARD_TYPE_IQD:
  854. return 1;
  855. default:
  856. return 0;
  857. }
  858. }
  859. static inline int
  860. qeth_get_mtu_outof_framesize(int framesize)
  861. {
  862. switch (framesize) {
  863. case 0x4000:
  864. return 8192;
  865. case 0x6000:
  866. return 16384;
  867. case 0xa000:
  868. return 32768;
  869. case 0xffff:
  870. return 57344;
  871. default:
  872. return 0;
  873. }
  874. }
  875. static inline int
  876. qeth_mtu_is_valid(struct qeth_card * card, int mtu)
  877. {
  878. switch (card->info.type) {
  879. case QETH_CARD_TYPE_OSAE:
  880. return ((mtu >= 576) && (mtu <= 61440));
  881. case QETH_CARD_TYPE_IQD:
  882. return ((mtu >= 576) &&
  883. (mtu <= card->info.max_mtu + 4096 - 32));
  884. case QETH_CARD_TYPE_UNKNOWN:
  885. default:
  886. return 1;
  887. }
  888. }
  889. static inline int
  890. qeth_get_arphdr_type(int cardtype, int linktype)
  891. {
  892. switch (cardtype) {
  893. case QETH_CARD_TYPE_OSAE:
  894. switch (linktype) {
  895. case QETH_LINK_TYPE_LANE_TR:
  896. case QETH_LINK_TYPE_HSTR:
  897. return ARPHRD_IEEE802_TR;
  898. default:
  899. return ARPHRD_ETHER;
  900. }
  901. case QETH_CARD_TYPE_IQD:
  902. default:
  903. return ARPHRD_ETHER;
  904. }
  905. }
  906. #ifdef CONFIG_QETH_PERF_STATS
  907. static inline int
  908. qeth_get_micros(void)
  909. {
  910. return (int) (get_clock() >> 12);
  911. }
  912. #endif
  913. static inline int
  914. qeth_get_qdio_q_format(struct qeth_card *card)
  915. {
  916. switch (card->info.type) {
  917. case QETH_CARD_TYPE_IQD:
  918. return 2;
  919. default:
  920. return 0;
  921. }
  922. }
  923. static inline void
  924. qeth_ipaddr4_to_string(const __u8 *addr, char *buf)
  925. {
  926. sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
  927. }
  928. static inline int
  929. qeth_string_to_ipaddr4(const char *buf, __u8 *addr)
  930. {
  931. const char *start, *end;
  932. char abuf[4];
  933. char *tmp;
  934. int len;
  935. int i;
  936. start = buf;
  937. for (i = 0; i < 3; i++) {
  938. if (!(end = strchr(start, '.')))
  939. return -EINVAL;
  940. len = end - start;
  941. memset(abuf, 0, 4);
  942. strncpy(abuf, start, len);
  943. addr[i] = simple_strtoul(abuf, &tmp, 10);
  944. start = end + 1;
  945. }
  946. memset(abuf, 0, 4);
  947. strcpy(abuf, start);
  948. addr[3] = simple_strtoul(abuf, &tmp, 10);
  949. return 0;
  950. }
  951. static inline void
  952. qeth_ipaddr6_to_string(const __u8 *addr, char *buf)
  953. {
  954. sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
  955. ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
  956. addr[0], addr[1], addr[2], addr[3],
  957. addr[4], addr[5], addr[6], addr[7],
  958. addr[8], addr[9], addr[10], addr[11],
  959. addr[12], addr[13], addr[14], addr[15]);
  960. }
  961. static inline int
  962. qeth_string_to_ipaddr6(const char *buf, __u8 *addr)
  963. {
  964. const char *start, *end;
  965. u16 *tmp_addr;
  966. char abuf[5];
  967. char *tmp;
  968. int len;
  969. int i;
  970. tmp_addr = (u16 *)addr;
  971. start = buf;
  972. for (i = 0; i < 7; i++) {
  973. if (!(end = strchr(start, ':')))
  974. return -EINVAL;
  975. len = end - start;
  976. memset(abuf, 0, 5);
  977. strncpy(abuf, start, len);
  978. tmp_addr[i] = simple_strtoul(abuf, &tmp, 16);
  979. start = end + 1;
  980. }
  981. memset(abuf, 0, 5);
  982. strcpy(abuf, start);
  983. tmp_addr[7] = simple_strtoul(abuf, &tmp, 16);
  984. return 0;
  985. }
  986. static inline void
  987. qeth_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
  988. char *buf)
  989. {
  990. if (proto == QETH_PROT_IPV4)
  991. return qeth_ipaddr4_to_string(addr, buf);
  992. else if (proto == QETH_PROT_IPV6)
  993. return qeth_ipaddr6_to_string(addr, buf);
  994. }
  995. static inline int
  996. qeth_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
  997. __u8 *addr)
  998. {
  999. if (proto == QETH_PROT_IPV4)
  1000. return qeth_string_to_ipaddr4(buf, addr);
  1001. else if (proto == QETH_PROT_IPV6)
  1002. return qeth_string_to_ipaddr6(buf, addr);
  1003. else
  1004. return -EINVAL;
  1005. }
  1006. extern int
  1007. qeth_setrouting_v4(struct qeth_card *);
  1008. extern int
  1009. qeth_setrouting_v6(struct qeth_card *);
  1010. extern int
  1011. qeth_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
  1012. extern void
  1013. qeth_del_ipato_entry(struct qeth_card *, enum qeth_prot_versions, u8 *, int);
  1014. extern int
  1015. qeth_add_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
  1016. extern void
  1017. qeth_del_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
  1018. extern int
  1019. qeth_add_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
  1020. extern void
  1021. qeth_del_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
  1022. extern int
  1023. qeth_notifier_register(struct task_struct *, int );
  1024. extern int
  1025. qeth_notifier_unregister(struct task_struct * );
  1026. extern void
  1027. qeth_schedule_recovery(struct qeth_card *);
  1028. extern int
  1029. qeth_realloc_buffer_pool(struct qeth_card *, int);
  1030. extern int
  1031. qeth_set_large_send(struct qeth_card *);
  1032. extern void
  1033. qeth_fill_header(struct qeth_card *, struct qeth_hdr *,
  1034. struct sk_buff *, int, int);
  1035. extern void
  1036. qeth_flush_buffers(struct qeth_qdio_out_q *, int, int, int);
  1037. #endif /* __QETH_H__ */