qlcnic_sysfs.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  1. /*
  2. * QLogic qlcnic NIC Driver
  3. * Copyright (c) 2009-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qlcnic for copyright and licensing details.
  6. */
  7. #include <linux/slab.h>
  8. #include <linux/interrupt.h>
  9. #include "qlcnic.h"
  10. #include "qlcnic_hw.h"
  11. #include <linux/swab.h>
  12. #include <linux/dma-mapping.h>
  13. #include <net/ip.h>
  14. #include <linux/ipv6.h>
  15. #include <linux/inetdevice.h>
  16. #include <linux/sysfs.h>
  17. #include <linux/aer.h>
  18. #include <linux/log2.h>
  19. #define QLC_STATUS_UNSUPPORTED_CMD -2
  20. int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable)
  21. {
  22. return -EOPNOTSUPP;
  23. }
  24. int qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate)
  25. {
  26. return -EOPNOTSUPP;
  27. }
  28. static ssize_t qlcnic_store_bridged_mode(struct device *dev,
  29. struct device_attribute *attr,
  30. const char *buf, size_t len)
  31. {
  32. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  33. unsigned long new;
  34. int ret = -EINVAL;
  35. if (!(adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_BDG))
  36. goto err_out;
  37. if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
  38. goto err_out;
  39. if (kstrtoul(buf, 2, &new))
  40. goto err_out;
  41. if (!qlcnic_config_bridged_mode(adapter, !!new))
  42. ret = len;
  43. err_out:
  44. return ret;
  45. }
  46. static ssize_t qlcnic_show_bridged_mode(struct device *dev,
  47. struct device_attribute *attr,
  48. char *buf)
  49. {
  50. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  51. int bridged_mode = 0;
  52. if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_BDG)
  53. bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED);
  54. return sprintf(buf, "%d\n", bridged_mode);
  55. }
  56. static ssize_t qlcnic_store_diag_mode(struct device *dev,
  57. struct device_attribute *attr,
  58. const char *buf, size_t len)
  59. {
  60. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  61. unsigned long new;
  62. if (kstrtoul(buf, 2, &new))
  63. return -EINVAL;
  64. if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED))
  65. adapter->flags ^= QLCNIC_DIAG_ENABLED;
  66. return len;
  67. }
  68. static ssize_t qlcnic_show_diag_mode(struct device *dev,
  69. struct device_attribute *attr, char *buf)
  70. {
  71. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  72. return sprintf(buf, "%d\n", !!(adapter->flags & QLCNIC_DIAG_ENABLED));
  73. }
  74. static int qlcnic_validate_beacon(struct qlcnic_adapter *adapter, u16 beacon,
  75. u8 *state, u8 *rate)
  76. {
  77. *rate = LSB(beacon);
  78. *state = MSB(beacon);
  79. QLCDB(adapter, DRV, "rate %x state %x\n", *rate, *state);
  80. if (!*state) {
  81. *rate = __QLCNIC_MAX_LED_RATE;
  82. return 0;
  83. } else if (*state > __QLCNIC_MAX_LED_STATE) {
  84. return -EINVAL;
  85. }
  86. if ((!*rate) || (*rate > __QLCNIC_MAX_LED_RATE))
  87. return -EINVAL;
  88. return 0;
  89. }
  90. static int qlcnic_83xx_store_beacon(struct qlcnic_adapter *adapter,
  91. const char *buf, size_t len)
  92. {
  93. struct qlcnic_hardware_context *ahw = adapter->ahw;
  94. unsigned long h_beacon;
  95. int err;
  96. if (test_bit(__QLCNIC_RESETTING, &adapter->state))
  97. return -EIO;
  98. if (kstrtoul(buf, 2, &h_beacon))
  99. return -EINVAL;
  100. qlcnic_get_beacon_state(adapter);
  101. if (ahw->beacon_state == h_beacon)
  102. return len;
  103. rtnl_lock();
  104. if (!ahw->beacon_state) {
  105. if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state)) {
  106. rtnl_unlock();
  107. return -EBUSY;
  108. }
  109. }
  110. if (h_beacon)
  111. err = qlcnic_83xx_config_led(adapter, 1, h_beacon);
  112. else
  113. err = qlcnic_83xx_config_led(adapter, 0, !h_beacon);
  114. if (!err)
  115. ahw->beacon_state = h_beacon;
  116. if (!ahw->beacon_state)
  117. clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
  118. rtnl_unlock();
  119. return len;
  120. }
  121. static int qlcnic_82xx_store_beacon(struct qlcnic_adapter *adapter,
  122. const char *buf, size_t len)
  123. {
  124. struct qlcnic_hardware_context *ahw = adapter->ahw;
  125. int err, drv_sds_rings = adapter->drv_sds_rings;
  126. u16 beacon;
  127. u8 b_state, b_rate;
  128. if (len != sizeof(u16))
  129. return QL_STATUS_INVALID_PARAM;
  130. memcpy(&beacon, buf, sizeof(u16));
  131. err = qlcnic_validate_beacon(adapter, beacon, &b_state, &b_rate);
  132. if (err)
  133. return err;
  134. qlcnic_get_beacon_state(adapter);
  135. if (ahw->beacon_state == b_state)
  136. return len;
  137. rtnl_lock();
  138. if (!ahw->beacon_state) {
  139. if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state)) {
  140. rtnl_unlock();
  141. return -EBUSY;
  142. }
  143. }
  144. if (test_bit(__QLCNIC_RESETTING, &adapter->state)) {
  145. err = -EIO;
  146. goto out;
  147. }
  148. if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
  149. err = qlcnic_diag_alloc_res(adapter->netdev, QLCNIC_LED_TEST);
  150. if (err)
  151. goto out;
  152. set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
  153. }
  154. err = qlcnic_config_led(adapter, b_state, b_rate);
  155. if (!err) {
  156. err = len;
  157. ahw->beacon_state = b_state;
  158. }
  159. if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state))
  160. qlcnic_diag_free_res(adapter->netdev, drv_sds_rings);
  161. out:
  162. if (!ahw->beacon_state)
  163. clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
  164. rtnl_unlock();
  165. return err;
  166. }
  167. static ssize_t qlcnic_store_beacon(struct device *dev,
  168. struct device_attribute *attr,
  169. const char *buf, size_t len)
  170. {
  171. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  172. int err = 0;
  173. if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
  174. dev_warn(dev,
  175. "LED test not supported in non privileged mode\n");
  176. return -EOPNOTSUPP;
  177. }
  178. if (qlcnic_82xx_check(adapter))
  179. err = qlcnic_82xx_store_beacon(adapter, buf, len);
  180. else if (qlcnic_83xx_check(adapter))
  181. err = qlcnic_83xx_store_beacon(adapter, buf, len);
  182. else
  183. return -EIO;
  184. return err;
  185. }
  186. static ssize_t qlcnic_show_beacon(struct device *dev,
  187. struct device_attribute *attr, char *buf)
  188. {
  189. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  190. return sprintf(buf, "%d\n", adapter->ahw->beacon_state);
  191. }
  192. static int qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter,
  193. loff_t offset, size_t size)
  194. {
  195. size_t crb_size = 4;
  196. if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
  197. return -EIO;
  198. if (offset < QLCNIC_PCI_CRBSPACE) {
  199. if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM,
  200. QLCNIC_PCI_CAMQM_END))
  201. crb_size = 8;
  202. else
  203. return -EINVAL;
  204. }
  205. if ((size != crb_size) || (offset & (crb_size-1)))
  206. return -EINVAL;
  207. return 0;
  208. }
  209. static ssize_t qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj,
  210. struct bin_attribute *attr, char *buf,
  211. loff_t offset, size_t size)
  212. {
  213. struct device *dev = container_of(kobj, struct device, kobj);
  214. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  215. int ret;
  216. ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
  217. if (ret != 0)
  218. return ret;
  219. qlcnic_read_crb(adapter, buf, offset, size);
  220. return size;
  221. }
  222. static ssize_t qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj,
  223. struct bin_attribute *attr, char *buf,
  224. loff_t offset, size_t size)
  225. {
  226. struct device *dev = container_of(kobj, struct device, kobj);
  227. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  228. int ret;
  229. ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
  230. if (ret != 0)
  231. return ret;
  232. qlcnic_write_crb(adapter, buf, offset, size);
  233. return size;
  234. }
  235. static int qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter,
  236. loff_t offset, size_t size)
  237. {
  238. if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
  239. return -EIO;
  240. if ((size != 8) || (offset & 0x7))
  241. return -EIO;
  242. return 0;
  243. }
  244. static ssize_t qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj,
  245. struct bin_attribute *attr, char *buf,
  246. loff_t offset, size_t size)
  247. {
  248. struct device *dev = container_of(kobj, struct device, kobj);
  249. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  250. u64 data;
  251. int ret;
  252. ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
  253. if (ret != 0)
  254. return ret;
  255. if (qlcnic_pci_mem_read_2M(adapter, offset, &data))
  256. return -EIO;
  257. memcpy(buf, &data, size);
  258. return size;
  259. }
  260. static ssize_t qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj,
  261. struct bin_attribute *attr, char *buf,
  262. loff_t offset, size_t size)
  263. {
  264. struct device *dev = container_of(kobj, struct device, kobj);
  265. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  266. u64 data;
  267. int ret;
  268. ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
  269. if (ret != 0)
  270. return ret;
  271. memcpy(&data, buf, size);
  272. if (qlcnic_pci_mem_write_2M(adapter, offset, data))
  273. return -EIO;
  274. return size;
  275. }
  276. static u32 qlcnic_get_pci_func_count(struct qlcnic_adapter *adapter)
  277. {
  278. struct qlcnic_hardware_context *ahw = adapter->ahw;
  279. u32 count = 0;
  280. if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
  281. return ahw->total_nic_func;
  282. if (ahw->total_pci_func <= QLC_DEFAULT_VNIC_COUNT)
  283. count = QLC_DEFAULT_VNIC_COUNT;
  284. else
  285. count = ahw->max_vnic_func;
  286. return count;
  287. }
  288. int qlcnic_is_valid_nic_func(struct qlcnic_adapter *adapter, u8 pci_func)
  289. {
  290. u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
  291. int i;
  292. for (i = 0; i < pci_func_count; i++) {
  293. if (adapter->npars[i].pci_func == pci_func)
  294. return i;
  295. }
  296. return -1;
  297. }
  298. static int validate_pm_config(struct qlcnic_adapter *adapter,
  299. struct qlcnic_pm_func_cfg *pm_cfg, int count)
  300. {
  301. u8 src_pci_func, s_esw_id, d_esw_id;
  302. u8 dest_pci_func;
  303. int i, src_index, dest_index;
  304. for (i = 0; i < count; i++) {
  305. src_pci_func = pm_cfg[i].pci_func;
  306. dest_pci_func = pm_cfg[i].dest_npar;
  307. src_index = qlcnic_is_valid_nic_func(adapter, src_pci_func);
  308. if (src_index < 0)
  309. return QL_STATUS_INVALID_PARAM;
  310. dest_index = qlcnic_is_valid_nic_func(adapter, dest_pci_func);
  311. if (dest_index < 0)
  312. return QL_STATUS_INVALID_PARAM;
  313. s_esw_id = adapter->npars[src_index].phy_port;
  314. d_esw_id = adapter->npars[dest_index].phy_port;
  315. if (s_esw_id != d_esw_id)
  316. return QL_STATUS_INVALID_PARAM;
  317. }
  318. return 0;
  319. }
  320. static ssize_t qlcnic_sysfs_write_pm_config(struct file *filp,
  321. struct kobject *kobj,
  322. struct bin_attribute *attr,
  323. char *buf, loff_t offset,
  324. size_t size)
  325. {
  326. struct device *dev = container_of(kobj, struct device, kobj);
  327. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  328. struct qlcnic_pm_func_cfg *pm_cfg;
  329. u32 id, action, pci_func;
  330. int count, rem, i, ret, index;
  331. count = size / sizeof(struct qlcnic_pm_func_cfg);
  332. rem = size % sizeof(struct qlcnic_pm_func_cfg);
  333. if (rem)
  334. return QL_STATUS_INVALID_PARAM;
  335. pm_cfg = (struct qlcnic_pm_func_cfg *)buf;
  336. ret = validate_pm_config(adapter, pm_cfg, count);
  337. if (ret)
  338. return ret;
  339. for (i = 0; i < count; i++) {
  340. pci_func = pm_cfg[i].pci_func;
  341. action = !!pm_cfg[i].action;
  342. index = qlcnic_is_valid_nic_func(adapter, pci_func);
  343. if (index < 0)
  344. return QL_STATUS_INVALID_PARAM;
  345. id = adapter->npars[index].phy_port;
  346. ret = qlcnic_config_port_mirroring(adapter, id,
  347. action, pci_func);
  348. if (ret)
  349. return ret;
  350. }
  351. for (i = 0; i < count; i++) {
  352. pci_func = pm_cfg[i].pci_func;
  353. index = qlcnic_is_valid_nic_func(adapter, pci_func);
  354. if (index < 0)
  355. return QL_STATUS_INVALID_PARAM;
  356. id = adapter->npars[index].phy_port;
  357. adapter->npars[index].enable_pm = !!pm_cfg[i].action;
  358. adapter->npars[index].dest_npar = id;
  359. }
  360. return size;
  361. }
  362. static ssize_t qlcnic_sysfs_read_pm_config(struct file *filp,
  363. struct kobject *kobj,
  364. struct bin_attribute *attr,
  365. char *buf, loff_t offset,
  366. size_t size)
  367. {
  368. struct device *dev = container_of(kobj, struct device, kobj);
  369. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  370. u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
  371. struct qlcnic_pm_func_cfg *pm_cfg;
  372. int i, pm_cfg_size;
  373. u8 pci_func;
  374. pm_cfg_size = pci_func_count * sizeof(*pm_cfg);
  375. if (size != pm_cfg_size)
  376. return QL_STATUS_INVALID_PARAM;
  377. memset(buf, 0, pm_cfg_size);
  378. pm_cfg = (struct qlcnic_pm_func_cfg *)buf;
  379. for (i = 0; i < pci_func_count; i++) {
  380. pci_func = adapter->npars[i].pci_func;
  381. if (!adapter->npars[i].active)
  382. continue;
  383. if (!adapter->npars[i].eswitch_status)
  384. continue;
  385. pm_cfg[pci_func].action = adapter->npars[i].enable_pm;
  386. pm_cfg[pci_func].dest_npar = 0;
  387. pm_cfg[pci_func].pci_func = i;
  388. }
  389. return size;
  390. }
  391. static int validate_esw_config(struct qlcnic_adapter *adapter,
  392. struct qlcnic_esw_func_cfg *esw_cfg, int count)
  393. {
  394. u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
  395. struct qlcnic_hardware_context *ahw = adapter->ahw;
  396. int i, ret;
  397. u32 op_mode;
  398. u8 pci_func;
  399. if (qlcnic_82xx_check(adapter))
  400. op_mode = readl(ahw->pci_base0 + QLCNIC_DRV_OP_MODE);
  401. else
  402. op_mode = QLCRDX(ahw, QLC_83XX_DRV_OP_MODE);
  403. for (i = 0; i < count; i++) {
  404. pci_func = esw_cfg[i].pci_func;
  405. if (pci_func >= pci_func_count)
  406. return QL_STATUS_INVALID_PARAM;
  407. if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
  408. if (qlcnic_is_valid_nic_func(adapter, pci_func) < 0)
  409. return QL_STATUS_INVALID_PARAM;
  410. switch (esw_cfg[i].op_mode) {
  411. case QLCNIC_PORT_DEFAULTS:
  412. if (qlcnic_82xx_check(adapter)) {
  413. ret = QLC_DEV_GET_DRV(op_mode, pci_func);
  414. } else {
  415. ret = QLC_83XX_GET_FUNC_PRIVILEGE(op_mode,
  416. pci_func);
  417. esw_cfg[i].offload_flags = 0;
  418. }
  419. if (ret != QLCNIC_NON_PRIV_FUNC) {
  420. if (esw_cfg[i].mac_anti_spoof != 0)
  421. return QL_STATUS_INVALID_PARAM;
  422. if (esw_cfg[i].mac_override != 1)
  423. return QL_STATUS_INVALID_PARAM;
  424. if (esw_cfg[i].promisc_mode != 1)
  425. return QL_STATUS_INVALID_PARAM;
  426. }
  427. break;
  428. case QLCNIC_ADD_VLAN:
  429. if (!IS_VALID_VLAN(esw_cfg[i].vlan_id))
  430. return QL_STATUS_INVALID_PARAM;
  431. if (!esw_cfg[i].op_type)
  432. return QL_STATUS_INVALID_PARAM;
  433. break;
  434. case QLCNIC_DEL_VLAN:
  435. if (!esw_cfg[i].op_type)
  436. return QL_STATUS_INVALID_PARAM;
  437. break;
  438. default:
  439. return QL_STATUS_INVALID_PARAM;
  440. }
  441. }
  442. return 0;
  443. }
  444. static ssize_t qlcnic_sysfs_write_esw_config(struct file *file,
  445. struct kobject *kobj,
  446. struct bin_attribute *attr,
  447. char *buf, loff_t offset,
  448. size_t size)
  449. {
  450. struct device *dev = container_of(kobj, struct device, kobj);
  451. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  452. struct qlcnic_esw_func_cfg *esw_cfg;
  453. struct qlcnic_npar_info *npar;
  454. int count, rem, i, ret;
  455. int index;
  456. u8 op_mode = 0, pci_func;
  457. count = size / sizeof(struct qlcnic_esw_func_cfg);
  458. rem = size % sizeof(struct qlcnic_esw_func_cfg);
  459. if (rem)
  460. return QL_STATUS_INVALID_PARAM;
  461. esw_cfg = (struct qlcnic_esw_func_cfg *)buf;
  462. ret = validate_esw_config(adapter, esw_cfg, count);
  463. if (ret)
  464. return ret;
  465. for (i = 0; i < count; i++) {
  466. if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
  467. if (qlcnic_config_switch_port(adapter, &esw_cfg[i]))
  468. return QL_STATUS_INVALID_PARAM;
  469. if (adapter->ahw->pci_func != esw_cfg[i].pci_func)
  470. continue;
  471. op_mode = esw_cfg[i].op_mode;
  472. qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]);
  473. esw_cfg[i].op_mode = op_mode;
  474. esw_cfg[i].pci_func = adapter->ahw->pci_func;
  475. switch (esw_cfg[i].op_mode) {
  476. case QLCNIC_PORT_DEFAULTS:
  477. qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]);
  478. rtnl_lock();
  479. qlcnic_set_netdev_features(adapter, &esw_cfg[i]);
  480. rtnl_unlock();
  481. break;
  482. case QLCNIC_ADD_VLAN:
  483. qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
  484. break;
  485. case QLCNIC_DEL_VLAN:
  486. esw_cfg[i].vlan_id = 0;
  487. qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
  488. break;
  489. }
  490. }
  491. if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
  492. goto out;
  493. for (i = 0; i < count; i++) {
  494. pci_func = esw_cfg[i].pci_func;
  495. index = qlcnic_is_valid_nic_func(adapter, pci_func);
  496. if (index < 0)
  497. return QL_STATUS_INVALID_PARAM;
  498. npar = &adapter->npars[index];
  499. switch (esw_cfg[i].op_mode) {
  500. case QLCNIC_PORT_DEFAULTS:
  501. npar->promisc_mode = esw_cfg[i].promisc_mode;
  502. npar->mac_override = esw_cfg[i].mac_override;
  503. npar->offload_flags = esw_cfg[i].offload_flags;
  504. npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof;
  505. npar->discard_tagged = esw_cfg[i].discard_tagged;
  506. break;
  507. case QLCNIC_ADD_VLAN:
  508. npar->pvid = esw_cfg[i].vlan_id;
  509. break;
  510. case QLCNIC_DEL_VLAN:
  511. npar->pvid = 0;
  512. break;
  513. }
  514. }
  515. out:
  516. return size;
  517. }
  518. static ssize_t qlcnic_sysfs_read_esw_config(struct file *file,
  519. struct kobject *kobj,
  520. struct bin_attribute *attr,
  521. char *buf, loff_t offset,
  522. size_t size)
  523. {
  524. struct device *dev = container_of(kobj, struct device, kobj);
  525. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  526. u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
  527. struct qlcnic_esw_func_cfg *esw_cfg;
  528. size_t esw_cfg_size;
  529. u8 i, pci_func;
  530. esw_cfg_size = pci_func_count * sizeof(*esw_cfg);
  531. if (size != esw_cfg_size)
  532. return QL_STATUS_INVALID_PARAM;
  533. memset(buf, 0, esw_cfg_size);
  534. esw_cfg = (struct qlcnic_esw_func_cfg *)buf;
  535. for (i = 0; i < pci_func_count; i++) {
  536. pci_func = adapter->npars[i].pci_func;
  537. if (!adapter->npars[i].active)
  538. continue;
  539. if (!adapter->npars[i].eswitch_status)
  540. continue;
  541. esw_cfg[pci_func].pci_func = pci_func;
  542. if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[pci_func]))
  543. return QL_STATUS_INVALID_PARAM;
  544. }
  545. return size;
  546. }
  547. static int validate_npar_config(struct qlcnic_adapter *adapter,
  548. struct qlcnic_npar_func_cfg *np_cfg,
  549. int count)
  550. {
  551. u8 pci_func, i;
  552. for (i = 0; i < count; i++) {
  553. pci_func = np_cfg[i].pci_func;
  554. if (qlcnic_is_valid_nic_func(adapter, pci_func) < 0)
  555. return QL_STATUS_INVALID_PARAM;
  556. if (!IS_VALID_BW(np_cfg[i].min_bw) ||
  557. !IS_VALID_BW(np_cfg[i].max_bw))
  558. return QL_STATUS_INVALID_PARAM;
  559. }
  560. return 0;
  561. }
  562. static ssize_t qlcnic_sysfs_write_npar_config(struct file *file,
  563. struct kobject *kobj,
  564. struct bin_attribute *attr,
  565. char *buf, loff_t offset,
  566. size_t size)
  567. {
  568. struct device *dev = container_of(kobj, struct device, kobj);
  569. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  570. struct qlcnic_info nic_info;
  571. struct qlcnic_npar_func_cfg *np_cfg;
  572. int i, count, rem, ret, index;
  573. u8 pci_func;
  574. count = size / sizeof(struct qlcnic_npar_func_cfg);
  575. rem = size % sizeof(struct qlcnic_npar_func_cfg);
  576. if (rem)
  577. return QL_STATUS_INVALID_PARAM;
  578. np_cfg = (struct qlcnic_npar_func_cfg *)buf;
  579. ret = validate_npar_config(adapter, np_cfg, count);
  580. if (ret)
  581. return ret;
  582. for (i = 0; i < count; i++) {
  583. pci_func = np_cfg[i].pci_func;
  584. memset(&nic_info, 0, sizeof(struct qlcnic_info));
  585. ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
  586. if (ret)
  587. return ret;
  588. nic_info.pci_func = pci_func;
  589. nic_info.min_tx_bw = np_cfg[i].min_bw;
  590. nic_info.max_tx_bw = np_cfg[i].max_bw;
  591. ret = qlcnic_set_nic_info(adapter, &nic_info);
  592. if (ret)
  593. return ret;
  594. index = qlcnic_is_valid_nic_func(adapter, pci_func);
  595. if (index < 0)
  596. return QL_STATUS_INVALID_PARAM;
  597. adapter->npars[index].min_bw = nic_info.min_tx_bw;
  598. adapter->npars[index].max_bw = nic_info.max_tx_bw;
  599. }
  600. return size;
  601. }
  602. static ssize_t qlcnic_sysfs_read_npar_config(struct file *file,
  603. struct kobject *kobj,
  604. struct bin_attribute *attr,
  605. char *buf, loff_t offset,
  606. size_t size)
  607. {
  608. struct device *dev = container_of(kobj, struct device, kobj);
  609. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  610. u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
  611. struct qlcnic_npar_func_cfg *np_cfg;
  612. struct qlcnic_info nic_info;
  613. size_t np_cfg_size;
  614. int i, ret;
  615. np_cfg_size = pci_func_count * sizeof(*np_cfg);
  616. if (size != np_cfg_size)
  617. return QL_STATUS_INVALID_PARAM;
  618. memset(&nic_info, 0, sizeof(struct qlcnic_info));
  619. memset(buf, 0, np_cfg_size);
  620. np_cfg = (struct qlcnic_npar_func_cfg *)buf;
  621. for (i = 0; i < pci_func_count; i++) {
  622. if (qlcnic_is_valid_nic_func(adapter, i) < 0)
  623. continue;
  624. ret = qlcnic_get_nic_info(adapter, &nic_info, i);
  625. if (ret)
  626. return ret;
  627. if (!adapter->npars[i].eswitch_status)
  628. continue;
  629. np_cfg[i].pci_func = i;
  630. np_cfg[i].op_mode = (u8)nic_info.op_mode;
  631. np_cfg[i].port_num = nic_info.phys_port;
  632. np_cfg[i].fw_capab = nic_info.capabilities;
  633. np_cfg[i].min_bw = nic_info.min_tx_bw;
  634. np_cfg[i].max_bw = nic_info.max_tx_bw;
  635. np_cfg[i].max_tx_queues = nic_info.max_tx_ques;
  636. np_cfg[i].max_rx_queues = nic_info.max_rx_ques;
  637. }
  638. return size;
  639. }
  640. static ssize_t qlcnic_sysfs_get_port_stats(struct file *file,
  641. struct kobject *kobj,
  642. struct bin_attribute *attr,
  643. char *buf, loff_t offset,
  644. size_t size)
  645. {
  646. struct device *dev = container_of(kobj, struct device, kobj);
  647. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  648. u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
  649. struct qlcnic_esw_statistics port_stats;
  650. int ret;
  651. if (qlcnic_83xx_check(adapter))
  652. return QLC_STATUS_UNSUPPORTED_CMD;
  653. if (size != sizeof(struct qlcnic_esw_statistics))
  654. return QL_STATUS_INVALID_PARAM;
  655. if (offset >= pci_func_count)
  656. return QL_STATUS_INVALID_PARAM;
  657. memset(&port_stats, 0, size);
  658. ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
  659. &port_stats.rx);
  660. if (ret)
  661. return ret;
  662. ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
  663. &port_stats.tx);
  664. if (ret)
  665. return ret;
  666. memcpy(buf, &port_stats, size);
  667. return size;
  668. }
  669. static ssize_t qlcnic_sysfs_get_esw_stats(struct file *file,
  670. struct kobject *kobj,
  671. struct bin_attribute *attr,
  672. char *buf, loff_t offset,
  673. size_t size)
  674. {
  675. struct device *dev = container_of(kobj, struct device, kobj);
  676. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  677. struct qlcnic_esw_statistics esw_stats;
  678. int ret;
  679. if (qlcnic_83xx_check(adapter))
  680. return QLC_STATUS_UNSUPPORTED_CMD;
  681. if (size != sizeof(struct qlcnic_esw_statistics))
  682. return QL_STATUS_INVALID_PARAM;
  683. if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
  684. return QL_STATUS_INVALID_PARAM;
  685. memset(&esw_stats, 0, size);
  686. ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
  687. &esw_stats.rx);
  688. if (ret)
  689. return ret;
  690. ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
  691. &esw_stats.tx);
  692. if (ret)
  693. return ret;
  694. memcpy(buf, &esw_stats, size);
  695. return size;
  696. }
  697. static ssize_t qlcnic_sysfs_clear_esw_stats(struct file *file,
  698. struct kobject *kobj,
  699. struct bin_attribute *attr,
  700. char *buf, loff_t offset,
  701. size_t size)
  702. {
  703. struct device *dev = container_of(kobj, struct device, kobj);
  704. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  705. int ret;
  706. if (qlcnic_83xx_check(adapter))
  707. return QLC_STATUS_UNSUPPORTED_CMD;
  708. if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
  709. return QL_STATUS_INVALID_PARAM;
  710. ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
  711. QLCNIC_QUERY_RX_COUNTER);
  712. if (ret)
  713. return ret;
  714. ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
  715. QLCNIC_QUERY_TX_COUNTER);
  716. if (ret)
  717. return ret;
  718. return size;
  719. }
  720. static ssize_t qlcnic_sysfs_clear_port_stats(struct file *file,
  721. struct kobject *kobj,
  722. struct bin_attribute *attr,
  723. char *buf, loff_t offset,
  724. size_t size)
  725. {
  726. struct device *dev = container_of(kobj, struct device, kobj);
  727. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  728. u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
  729. int ret;
  730. if (qlcnic_83xx_check(adapter))
  731. return QLC_STATUS_UNSUPPORTED_CMD;
  732. if (offset >= pci_func_count)
  733. return QL_STATUS_INVALID_PARAM;
  734. ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
  735. QLCNIC_QUERY_RX_COUNTER);
  736. if (ret)
  737. return ret;
  738. ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
  739. QLCNIC_QUERY_TX_COUNTER);
  740. if (ret)
  741. return ret;
  742. return size;
  743. }
  744. static ssize_t qlcnic_sysfs_read_pci_config(struct file *file,
  745. struct kobject *kobj,
  746. struct bin_attribute *attr,
  747. char *buf, loff_t offset,
  748. size_t size)
  749. {
  750. struct device *dev = container_of(kobj, struct device, kobj);
  751. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  752. u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
  753. struct qlcnic_pci_func_cfg *pci_cfg;
  754. struct qlcnic_pci_info *pci_info;
  755. size_t pci_cfg_sz;
  756. int i, ret;
  757. pci_cfg_sz = pci_func_count * sizeof(*pci_cfg);
  758. if (size != pci_cfg_sz)
  759. return QL_STATUS_INVALID_PARAM;
  760. pci_info = kcalloc(pci_func_count, sizeof(*pci_info), GFP_KERNEL);
  761. if (!pci_info)
  762. return -ENOMEM;
  763. ret = qlcnic_get_pci_info(adapter, pci_info);
  764. if (ret) {
  765. kfree(pci_info);
  766. return ret;
  767. }
  768. pci_cfg = (struct qlcnic_pci_func_cfg *)buf;
  769. for (i = 0; i < pci_func_count; i++) {
  770. pci_cfg[i].pci_func = pci_info[i].id;
  771. pci_cfg[i].func_type = pci_info[i].type;
  772. pci_cfg[i].func_state = 0;
  773. pci_cfg[i].port_num = pci_info[i].default_port;
  774. pci_cfg[i].min_bw = pci_info[i].tx_min_bw;
  775. pci_cfg[i].max_bw = pci_info[i].tx_max_bw;
  776. memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN);
  777. }
  778. kfree(pci_info);
  779. return size;
  780. }
  781. static ssize_t qlcnic_83xx_sysfs_flash_read_handler(struct file *filp,
  782. struct kobject *kobj,
  783. struct bin_attribute *attr,
  784. char *buf, loff_t offset,
  785. size_t size)
  786. {
  787. unsigned char *p_read_buf;
  788. int ret, count;
  789. struct device *dev = container_of(kobj, struct device, kobj);
  790. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  791. if (!size)
  792. return QL_STATUS_INVALID_PARAM;
  793. if (!buf)
  794. return QL_STATUS_INVALID_PARAM;
  795. count = size / sizeof(u32);
  796. if (size % sizeof(u32))
  797. count++;
  798. p_read_buf = kcalloc(size, sizeof(unsigned char), GFP_KERNEL);
  799. if (!p_read_buf)
  800. return -ENOMEM;
  801. if (qlcnic_83xx_lock_flash(adapter) != 0) {
  802. kfree(p_read_buf);
  803. return -EIO;
  804. }
  805. ret = qlcnic_83xx_lockless_flash_read32(adapter, offset, p_read_buf,
  806. count);
  807. if (ret) {
  808. qlcnic_83xx_unlock_flash(adapter);
  809. kfree(p_read_buf);
  810. return ret;
  811. }
  812. qlcnic_83xx_unlock_flash(adapter);
  813. memcpy(buf, p_read_buf, size);
  814. kfree(p_read_buf);
  815. return size;
  816. }
  817. static int qlcnic_83xx_sysfs_flash_bulk_write(struct qlcnic_adapter *adapter,
  818. char *buf, loff_t offset,
  819. size_t size)
  820. {
  821. int i, ret, count;
  822. unsigned char *p_cache, *p_src;
  823. p_cache = kcalloc(size, sizeof(unsigned char), GFP_KERNEL);
  824. if (!p_cache)
  825. return -ENOMEM;
  826. memcpy(p_cache, buf, size);
  827. p_src = p_cache;
  828. count = size / sizeof(u32);
  829. if (qlcnic_83xx_lock_flash(adapter) != 0) {
  830. kfree(p_cache);
  831. return -EIO;
  832. }
  833. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  834. ret = qlcnic_83xx_enable_flash_write(adapter);
  835. if (ret) {
  836. kfree(p_cache);
  837. qlcnic_83xx_unlock_flash(adapter);
  838. return -EIO;
  839. }
  840. }
  841. for (i = 0; i < count / QLC_83XX_FLASH_WRITE_MAX; i++) {
  842. ret = qlcnic_83xx_flash_bulk_write(adapter, offset,
  843. (u32 *)p_src,
  844. QLC_83XX_FLASH_WRITE_MAX);
  845. if (ret) {
  846. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  847. ret = qlcnic_83xx_disable_flash_write(adapter);
  848. if (ret) {
  849. kfree(p_cache);
  850. qlcnic_83xx_unlock_flash(adapter);
  851. return -EIO;
  852. }
  853. }
  854. kfree(p_cache);
  855. qlcnic_83xx_unlock_flash(adapter);
  856. return -EIO;
  857. }
  858. p_src = p_src + sizeof(u32)*QLC_83XX_FLASH_WRITE_MAX;
  859. offset = offset + sizeof(u32)*QLC_83XX_FLASH_WRITE_MAX;
  860. }
  861. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  862. ret = qlcnic_83xx_disable_flash_write(adapter);
  863. if (ret) {
  864. kfree(p_cache);
  865. qlcnic_83xx_unlock_flash(adapter);
  866. return -EIO;
  867. }
  868. }
  869. kfree(p_cache);
  870. qlcnic_83xx_unlock_flash(adapter);
  871. return 0;
  872. }
  873. static int qlcnic_83xx_sysfs_flash_write(struct qlcnic_adapter *adapter,
  874. char *buf, loff_t offset, size_t size)
  875. {
  876. int i, ret, count;
  877. unsigned char *p_cache, *p_src;
  878. p_cache = kcalloc(size, sizeof(unsigned char), GFP_KERNEL);
  879. if (!p_cache)
  880. return -ENOMEM;
  881. memcpy(p_cache, buf, size);
  882. p_src = p_cache;
  883. count = size / sizeof(u32);
  884. if (qlcnic_83xx_lock_flash(adapter) != 0) {
  885. kfree(p_cache);
  886. return -EIO;
  887. }
  888. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  889. ret = qlcnic_83xx_enable_flash_write(adapter);
  890. if (ret) {
  891. kfree(p_cache);
  892. qlcnic_83xx_unlock_flash(adapter);
  893. return -EIO;
  894. }
  895. }
  896. for (i = 0; i < count; i++) {
  897. ret = qlcnic_83xx_flash_write32(adapter, offset, (u32 *)p_src);
  898. if (ret) {
  899. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  900. ret = qlcnic_83xx_disable_flash_write(adapter);
  901. if (ret) {
  902. kfree(p_cache);
  903. qlcnic_83xx_unlock_flash(adapter);
  904. return -EIO;
  905. }
  906. }
  907. kfree(p_cache);
  908. qlcnic_83xx_unlock_flash(adapter);
  909. return -EIO;
  910. }
  911. p_src = p_src + sizeof(u32);
  912. offset = offset + sizeof(u32);
  913. }
  914. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  915. ret = qlcnic_83xx_disable_flash_write(adapter);
  916. if (ret) {
  917. kfree(p_cache);
  918. qlcnic_83xx_unlock_flash(adapter);
  919. return -EIO;
  920. }
  921. }
  922. kfree(p_cache);
  923. qlcnic_83xx_unlock_flash(adapter);
  924. return 0;
  925. }
  926. static ssize_t qlcnic_83xx_sysfs_flash_write_handler(struct file *filp,
  927. struct kobject *kobj,
  928. struct bin_attribute *attr,
  929. char *buf, loff_t offset,
  930. size_t size)
  931. {
  932. int ret;
  933. static int flash_mode;
  934. unsigned long data;
  935. struct device *dev = container_of(kobj, struct device, kobj);
  936. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  937. if (!buf)
  938. return QL_STATUS_INVALID_PARAM;
  939. ret = kstrtoul(buf, 16, &data);
  940. switch (data) {
  941. case QLC_83XX_FLASH_SECTOR_ERASE_CMD:
  942. flash_mode = QLC_83XX_ERASE_MODE;
  943. ret = qlcnic_83xx_erase_flash_sector(adapter, offset);
  944. if (ret) {
  945. dev_err(&adapter->pdev->dev,
  946. "%s failed at %d\n", __func__, __LINE__);
  947. return -EIO;
  948. }
  949. break;
  950. case QLC_83XX_FLASH_BULK_WRITE_CMD:
  951. flash_mode = QLC_83XX_BULK_WRITE_MODE;
  952. break;
  953. case QLC_83XX_FLASH_WRITE_CMD:
  954. flash_mode = QLC_83XX_WRITE_MODE;
  955. break;
  956. default:
  957. if (flash_mode == QLC_83XX_BULK_WRITE_MODE) {
  958. ret = qlcnic_83xx_sysfs_flash_bulk_write(adapter, buf,
  959. offset, size);
  960. if (ret) {
  961. dev_err(&adapter->pdev->dev,
  962. "%s failed at %d\n",
  963. __func__, __LINE__);
  964. return -EIO;
  965. }
  966. }
  967. if (flash_mode == QLC_83XX_WRITE_MODE) {
  968. ret = qlcnic_83xx_sysfs_flash_write(adapter, buf,
  969. offset, size);
  970. if (ret) {
  971. dev_err(&adapter->pdev->dev,
  972. "%s failed at %d\n", __func__,
  973. __LINE__);
  974. return -EIO;
  975. }
  976. }
  977. }
  978. return size;
  979. }
  980. static struct device_attribute dev_attr_bridged_mode = {
  981. .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
  982. .show = qlcnic_show_bridged_mode,
  983. .store = qlcnic_store_bridged_mode,
  984. };
  985. static struct device_attribute dev_attr_diag_mode = {
  986. .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
  987. .show = qlcnic_show_diag_mode,
  988. .store = qlcnic_store_diag_mode,
  989. };
  990. static struct device_attribute dev_attr_beacon = {
  991. .attr = {.name = "beacon", .mode = (S_IRUGO | S_IWUSR)},
  992. .show = qlcnic_show_beacon,
  993. .store = qlcnic_store_beacon,
  994. };
  995. static struct bin_attribute bin_attr_crb = {
  996. .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
  997. .size = 0,
  998. .read = qlcnic_sysfs_read_crb,
  999. .write = qlcnic_sysfs_write_crb,
  1000. };
  1001. static struct bin_attribute bin_attr_mem = {
  1002. .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
  1003. .size = 0,
  1004. .read = qlcnic_sysfs_read_mem,
  1005. .write = qlcnic_sysfs_write_mem,
  1006. };
  1007. static struct bin_attribute bin_attr_npar_config = {
  1008. .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)},
  1009. .size = 0,
  1010. .read = qlcnic_sysfs_read_npar_config,
  1011. .write = qlcnic_sysfs_write_npar_config,
  1012. };
  1013. static struct bin_attribute bin_attr_pci_config = {
  1014. .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)},
  1015. .size = 0,
  1016. .read = qlcnic_sysfs_read_pci_config,
  1017. .write = NULL,
  1018. };
  1019. static struct bin_attribute bin_attr_port_stats = {
  1020. .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)},
  1021. .size = 0,
  1022. .read = qlcnic_sysfs_get_port_stats,
  1023. .write = qlcnic_sysfs_clear_port_stats,
  1024. };
  1025. static struct bin_attribute bin_attr_esw_stats = {
  1026. .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)},
  1027. .size = 0,
  1028. .read = qlcnic_sysfs_get_esw_stats,
  1029. .write = qlcnic_sysfs_clear_esw_stats,
  1030. };
  1031. static struct bin_attribute bin_attr_esw_config = {
  1032. .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)},
  1033. .size = 0,
  1034. .read = qlcnic_sysfs_read_esw_config,
  1035. .write = qlcnic_sysfs_write_esw_config,
  1036. };
  1037. static struct bin_attribute bin_attr_pm_config = {
  1038. .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)},
  1039. .size = 0,
  1040. .read = qlcnic_sysfs_read_pm_config,
  1041. .write = qlcnic_sysfs_write_pm_config,
  1042. };
  1043. static struct bin_attribute bin_attr_flash = {
  1044. .attr = {.name = "flash", .mode = (S_IRUGO | S_IWUSR)},
  1045. .size = 0,
  1046. .read = qlcnic_83xx_sysfs_flash_read_handler,
  1047. .write = qlcnic_83xx_sysfs_flash_write_handler,
  1048. };
  1049. void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter)
  1050. {
  1051. struct device *dev = &adapter->pdev->dev;
  1052. if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_BDG)
  1053. if (device_create_file(dev, &dev_attr_bridged_mode))
  1054. dev_warn(dev,
  1055. "failed to create bridged_mode sysfs entry\n");
  1056. }
  1057. void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter)
  1058. {
  1059. struct device *dev = &adapter->pdev->dev;
  1060. if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_BDG)
  1061. device_remove_file(dev, &dev_attr_bridged_mode);
  1062. }
  1063. static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter)
  1064. {
  1065. struct device *dev = &adapter->pdev->dev;
  1066. if (device_create_bin_file(dev, &bin_attr_port_stats))
  1067. dev_info(dev, "failed to create port stats sysfs entry");
  1068. if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC)
  1069. return;
  1070. if (device_create_file(dev, &dev_attr_diag_mode))
  1071. dev_info(dev, "failed to create diag_mode sysfs entry\n");
  1072. if (device_create_bin_file(dev, &bin_attr_crb))
  1073. dev_info(dev, "failed to create crb sysfs entry\n");
  1074. if (device_create_bin_file(dev, &bin_attr_mem))
  1075. dev_info(dev, "failed to create mem sysfs entry\n");
  1076. if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state))
  1077. return;
  1078. if (device_create_bin_file(dev, &bin_attr_pci_config))
  1079. dev_info(dev, "failed to create pci config sysfs entry");
  1080. if (device_create_file(dev, &dev_attr_beacon))
  1081. dev_info(dev, "failed to create beacon sysfs entry");
  1082. if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
  1083. return;
  1084. if (device_create_bin_file(dev, &bin_attr_esw_config))
  1085. dev_info(dev, "failed to create esw config sysfs entry");
  1086. if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
  1087. return;
  1088. if (device_create_bin_file(dev, &bin_attr_npar_config))
  1089. dev_info(dev, "failed to create npar config sysfs entry");
  1090. if (device_create_bin_file(dev, &bin_attr_pm_config))
  1091. dev_info(dev, "failed to create pm config sysfs entry");
  1092. if (device_create_bin_file(dev, &bin_attr_esw_stats))
  1093. dev_info(dev, "failed to create eswitch stats sysfs entry");
  1094. }
  1095. static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter)
  1096. {
  1097. struct device *dev = &adapter->pdev->dev;
  1098. device_remove_bin_file(dev, &bin_attr_port_stats);
  1099. if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC)
  1100. return;
  1101. device_remove_file(dev, &dev_attr_diag_mode);
  1102. device_remove_bin_file(dev, &bin_attr_crb);
  1103. device_remove_bin_file(dev, &bin_attr_mem);
  1104. if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state))
  1105. return;
  1106. device_remove_bin_file(dev, &bin_attr_pci_config);
  1107. device_remove_file(dev, &dev_attr_beacon);
  1108. if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
  1109. return;
  1110. device_remove_bin_file(dev, &bin_attr_esw_config);
  1111. if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
  1112. return;
  1113. device_remove_bin_file(dev, &bin_attr_npar_config);
  1114. device_remove_bin_file(dev, &bin_attr_pm_config);
  1115. device_remove_bin_file(dev, &bin_attr_esw_stats);
  1116. }
  1117. void qlcnic_82xx_add_sysfs(struct qlcnic_adapter *adapter)
  1118. {
  1119. qlcnic_create_diag_entries(adapter);
  1120. }
  1121. void qlcnic_82xx_remove_sysfs(struct qlcnic_adapter *adapter)
  1122. {
  1123. qlcnic_remove_diag_entries(adapter);
  1124. }
  1125. void qlcnic_83xx_add_sysfs(struct qlcnic_adapter *adapter)
  1126. {
  1127. struct device *dev = &adapter->pdev->dev;
  1128. qlcnic_create_diag_entries(adapter);
  1129. if (sysfs_create_bin_file(&dev->kobj, &bin_attr_flash))
  1130. dev_info(dev, "failed to create flash sysfs entry\n");
  1131. }
  1132. void qlcnic_83xx_remove_sysfs(struct qlcnic_adapter *adapter)
  1133. {
  1134. struct device *dev = &adapter->pdev->dev;
  1135. qlcnic_remove_diag_entries(adapter);
  1136. sysfs_remove_bin_file(&dev->kobj, &bin_attr_flash);
  1137. }