qlcnic_sysfs.c 34 KB

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