qlcnic_sysfs.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  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. netdev_err(adapter->netdev,
  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 < QLCNIC_MAX_PCI_FUNC; i++) {
  374. pci_func = adapter->npars[i].pci_func;
  375. if (!adapter->npars[i].active)
  376. continue;
  377. if (!adapter->npars[i].eswitch_status)
  378. continue;
  379. pm_cfg[pci_func].action = adapter->npars[i].enable_pm;
  380. pm_cfg[pci_func].dest_npar = 0;
  381. pm_cfg[pci_func].pci_func = i;
  382. }
  383. memcpy(buf, &pm_cfg, size);
  384. return size;
  385. }
  386. static int validate_esw_config(struct qlcnic_adapter *adapter,
  387. struct qlcnic_esw_func_cfg *esw_cfg, int count)
  388. {
  389. u32 op_mode;
  390. u8 pci_func;
  391. int i, ret;
  392. if (qlcnic_82xx_check(adapter))
  393. op_mode = readl(adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE);
  394. else
  395. op_mode = QLCRDX(adapter->ahw, QLC_83XX_DRV_OP_MODE);
  396. for (i = 0; i < count; i++) {
  397. pci_func = esw_cfg[i].pci_func;
  398. if (pci_func >= QLCNIC_MAX_PCI_FUNC)
  399. return QL_STATUS_INVALID_PARAM;
  400. if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
  401. if (qlcnic_is_valid_nic_func(adapter, pci_func) < 0)
  402. return QL_STATUS_INVALID_PARAM;
  403. switch (esw_cfg[i].op_mode) {
  404. case QLCNIC_PORT_DEFAULTS:
  405. if (qlcnic_82xx_check(adapter)) {
  406. ret = QLC_DEV_GET_DRV(op_mode, pci_func);
  407. } else {
  408. ret = QLC_83XX_GET_FUNC_PRIVILEGE(op_mode,
  409. pci_func);
  410. esw_cfg[i].offload_flags = 0;
  411. }
  412. if (ret != QLCNIC_NON_PRIV_FUNC) {
  413. if (esw_cfg[i].mac_anti_spoof != 0)
  414. return QL_STATUS_INVALID_PARAM;
  415. if (esw_cfg[i].mac_override != 1)
  416. return QL_STATUS_INVALID_PARAM;
  417. if (esw_cfg[i].promisc_mode != 1)
  418. return QL_STATUS_INVALID_PARAM;
  419. }
  420. break;
  421. case QLCNIC_ADD_VLAN:
  422. if (!IS_VALID_VLAN(esw_cfg[i].vlan_id))
  423. return QL_STATUS_INVALID_PARAM;
  424. if (!esw_cfg[i].op_type)
  425. return QL_STATUS_INVALID_PARAM;
  426. break;
  427. case QLCNIC_DEL_VLAN:
  428. if (!esw_cfg[i].op_type)
  429. return QL_STATUS_INVALID_PARAM;
  430. break;
  431. default:
  432. return QL_STATUS_INVALID_PARAM;
  433. }
  434. }
  435. return 0;
  436. }
  437. static ssize_t qlcnic_sysfs_write_esw_config(struct file *file,
  438. struct kobject *kobj,
  439. struct bin_attribute *attr,
  440. char *buf, loff_t offset,
  441. size_t size)
  442. {
  443. struct device *dev = container_of(kobj, struct device, kobj);
  444. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  445. struct qlcnic_esw_func_cfg *esw_cfg;
  446. struct qlcnic_npar_info *npar;
  447. int count, rem, i, ret;
  448. int index;
  449. u8 op_mode = 0, pci_func;
  450. count = size / sizeof(struct qlcnic_esw_func_cfg);
  451. rem = size % sizeof(struct qlcnic_esw_func_cfg);
  452. if (rem)
  453. return QL_STATUS_INVALID_PARAM;
  454. esw_cfg = (struct qlcnic_esw_func_cfg *)buf;
  455. ret = validate_esw_config(adapter, esw_cfg, count);
  456. if (ret)
  457. return ret;
  458. for (i = 0; i < count; i++) {
  459. if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
  460. if (qlcnic_config_switch_port(adapter, &esw_cfg[i]))
  461. return QL_STATUS_INVALID_PARAM;
  462. if (adapter->ahw->pci_func != esw_cfg[i].pci_func)
  463. continue;
  464. op_mode = esw_cfg[i].op_mode;
  465. qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]);
  466. esw_cfg[i].op_mode = op_mode;
  467. esw_cfg[i].pci_func = adapter->ahw->pci_func;
  468. switch (esw_cfg[i].op_mode) {
  469. case QLCNIC_PORT_DEFAULTS:
  470. qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]);
  471. rtnl_lock();
  472. qlcnic_set_netdev_features(adapter, &esw_cfg[i]);
  473. rtnl_unlock();
  474. break;
  475. case QLCNIC_ADD_VLAN:
  476. qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
  477. break;
  478. case QLCNIC_DEL_VLAN:
  479. esw_cfg[i].vlan_id = 0;
  480. qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
  481. break;
  482. }
  483. }
  484. if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
  485. goto out;
  486. for (i = 0; i < count; i++) {
  487. pci_func = esw_cfg[i].pci_func;
  488. index = qlcnic_is_valid_nic_func(adapter, pci_func);
  489. npar = &adapter->npars[index];
  490. switch (esw_cfg[i].op_mode) {
  491. case QLCNIC_PORT_DEFAULTS:
  492. npar->promisc_mode = esw_cfg[i].promisc_mode;
  493. npar->mac_override = esw_cfg[i].mac_override;
  494. npar->offload_flags = esw_cfg[i].offload_flags;
  495. npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof;
  496. npar->discard_tagged = esw_cfg[i].discard_tagged;
  497. break;
  498. case QLCNIC_ADD_VLAN:
  499. npar->pvid = esw_cfg[i].vlan_id;
  500. break;
  501. case QLCNIC_DEL_VLAN:
  502. npar->pvid = 0;
  503. break;
  504. }
  505. }
  506. out:
  507. return size;
  508. }
  509. static ssize_t qlcnic_sysfs_read_esw_config(struct file *file,
  510. struct kobject *kobj,
  511. struct bin_attribute *attr,
  512. char *buf, loff_t offset,
  513. size_t size)
  514. {
  515. struct device *dev = container_of(kobj, struct device, kobj);
  516. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  517. struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC];
  518. u8 i, pci_func;
  519. if (size != sizeof(esw_cfg))
  520. return QL_STATUS_INVALID_PARAM;
  521. memset(&esw_cfg, 0,
  522. sizeof(struct qlcnic_esw_func_cfg) * QLCNIC_MAX_PCI_FUNC);
  523. for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
  524. pci_func = adapter->npars[i].pci_func;
  525. if (!adapter->npars[i].active)
  526. continue;
  527. if (!adapter->npars[i].eswitch_status)
  528. continue;
  529. esw_cfg[pci_func].pci_func = pci_func;
  530. if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[pci_func]))
  531. return QL_STATUS_INVALID_PARAM;
  532. }
  533. memcpy(buf, &esw_cfg, size);
  534. return size;
  535. }
  536. static int validate_npar_config(struct qlcnic_adapter *adapter,
  537. struct qlcnic_npar_func_cfg *np_cfg,
  538. int count)
  539. {
  540. u8 pci_func, i;
  541. for (i = 0; i < count; i++) {
  542. pci_func = np_cfg[i].pci_func;
  543. if (qlcnic_is_valid_nic_func(adapter, pci_func) < 0)
  544. return QL_STATUS_INVALID_PARAM;
  545. if (!IS_VALID_BW(np_cfg[i].min_bw) ||
  546. !IS_VALID_BW(np_cfg[i].max_bw))
  547. return QL_STATUS_INVALID_PARAM;
  548. }
  549. return 0;
  550. }
  551. static ssize_t qlcnic_sysfs_write_npar_config(struct file *file,
  552. struct kobject *kobj,
  553. struct bin_attribute *attr,
  554. char *buf, loff_t offset,
  555. size_t size)
  556. {
  557. struct device *dev = container_of(kobj, struct device, kobj);
  558. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  559. struct qlcnic_info nic_info;
  560. struct qlcnic_npar_func_cfg *np_cfg;
  561. int i, count, rem, ret, index;
  562. u8 pci_func;
  563. count = size / sizeof(struct qlcnic_npar_func_cfg);
  564. rem = size % sizeof(struct qlcnic_npar_func_cfg);
  565. if (rem)
  566. return QL_STATUS_INVALID_PARAM;
  567. np_cfg = (struct qlcnic_npar_func_cfg *)buf;
  568. ret = validate_npar_config(adapter, np_cfg, count);
  569. if (ret)
  570. return ret;
  571. for (i = 0; i < count; i++) {
  572. pci_func = np_cfg[i].pci_func;
  573. memset(&nic_info, 0, sizeof(struct qlcnic_info));
  574. ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
  575. if (ret)
  576. return ret;
  577. nic_info.pci_func = pci_func;
  578. nic_info.min_tx_bw = np_cfg[i].min_bw;
  579. nic_info.max_tx_bw = np_cfg[i].max_bw;
  580. ret = qlcnic_set_nic_info(adapter, &nic_info);
  581. if (ret)
  582. return ret;
  583. index = qlcnic_is_valid_nic_func(adapter, pci_func);
  584. adapter->npars[index].min_bw = nic_info.min_tx_bw;
  585. adapter->npars[index].max_bw = nic_info.max_tx_bw;
  586. }
  587. return size;
  588. }
  589. static ssize_t qlcnic_sysfs_read_npar_config(struct file *file,
  590. struct kobject *kobj,
  591. struct bin_attribute *attr,
  592. char *buf, loff_t offset,
  593. size_t size)
  594. {
  595. struct device *dev = container_of(kobj, struct device, kobj);
  596. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  597. struct qlcnic_info nic_info;
  598. struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC];
  599. int i, ret;
  600. if (size != sizeof(np_cfg))
  601. return QL_STATUS_INVALID_PARAM;
  602. memset(&nic_info, 0, sizeof(struct qlcnic_info));
  603. memset(&np_cfg, 0,
  604. sizeof(struct qlcnic_npar_func_cfg) * QLCNIC_MAX_PCI_FUNC);
  605. for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
  606. if (qlcnic_is_valid_nic_func(adapter, i) < 0)
  607. continue;
  608. ret = qlcnic_get_nic_info(adapter, &nic_info, i);
  609. if (ret)
  610. return ret;
  611. if (!adapter->npars[i].eswitch_status)
  612. continue;
  613. np_cfg[i].pci_func = i;
  614. np_cfg[i].op_mode = (u8)nic_info.op_mode;
  615. np_cfg[i].port_num = nic_info.phys_port;
  616. np_cfg[i].fw_capab = nic_info.capabilities;
  617. np_cfg[i].min_bw = nic_info.min_tx_bw;
  618. np_cfg[i].max_bw = nic_info.max_tx_bw;
  619. np_cfg[i].max_tx_queues = nic_info.max_tx_ques;
  620. np_cfg[i].max_rx_queues = nic_info.max_rx_ques;
  621. }
  622. memcpy(buf, &np_cfg, size);
  623. return size;
  624. }
  625. static ssize_t qlcnic_sysfs_get_port_stats(struct file *file,
  626. struct kobject *kobj,
  627. struct bin_attribute *attr,
  628. char *buf, loff_t offset,
  629. size_t size)
  630. {
  631. struct device *dev = container_of(kobj, struct device, kobj);
  632. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  633. struct qlcnic_esw_statistics port_stats;
  634. int ret;
  635. if (qlcnic_83xx_check(adapter))
  636. return QLC_STATUS_UNSUPPORTED_CMD;
  637. if (size != sizeof(struct qlcnic_esw_statistics))
  638. return QL_STATUS_INVALID_PARAM;
  639. if (offset >= QLCNIC_MAX_PCI_FUNC)
  640. return QL_STATUS_INVALID_PARAM;
  641. memset(&port_stats, 0, size);
  642. ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
  643. &port_stats.rx);
  644. if (ret)
  645. return ret;
  646. ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
  647. &port_stats.tx);
  648. if (ret)
  649. return ret;
  650. memcpy(buf, &port_stats, size);
  651. return size;
  652. }
  653. static ssize_t qlcnic_sysfs_get_esw_stats(struct file *file,
  654. struct kobject *kobj,
  655. struct bin_attribute *attr,
  656. char *buf, loff_t offset,
  657. size_t size)
  658. {
  659. struct device *dev = container_of(kobj, struct device, kobj);
  660. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  661. struct qlcnic_esw_statistics esw_stats;
  662. int ret;
  663. if (qlcnic_83xx_check(adapter))
  664. return QLC_STATUS_UNSUPPORTED_CMD;
  665. if (size != sizeof(struct qlcnic_esw_statistics))
  666. return QL_STATUS_INVALID_PARAM;
  667. if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
  668. return QL_STATUS_INVALID_PARAM;
  669. memset(&esw_stats, 0, size);
  670. ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
  671. &esw_stats.rx);
  672. if (ret)
  673. return ret;
  674. ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
  675. &esw_stats.tx);
  676. if (ret)
  677. return ret;
  678. memcpy(buf, &esw_stats, size);
  679. return size;
  680. }
  681. static ssize_t qlcnic_sysfs_clear_esw_stats(struct file *file,
  682. struct kobject *kobj,
  683. struct bin_attribute *attr,
  684. char *buf, loff_t offset,
  685. size_t size)
  686. {
  687. struct device *dev = container_of(kobj, struct device, kobj);
  688. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  689. int ret;
  690. if (qlcnic_83xx_check(adapter))
  691. return QLC_STATUS_UNSUPPORTED_CMD;
  692. if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
  693. return QL_STATUS_INVALID_PARAM;
  694. ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
  695. QLCNIC_QUERY_RX_COUNTER);
  696. if (ret)
  697. return ret;
  698. ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
  699. QLCNIC_QUERY_TX_COUNTER);
  700. if (ret)
  701. return ret;
  702. return size;
  703. }
  704. static ssize_t qlcnic_sysfs_clear_port_stats(struct file *file,
  705. struct kobject *kobj,
  706. struct bin_attribute *attr,
  707. char *buf, loff_t offset,
  708. size_t size)
  709. {
  710. struct device *dev = container_of(kobj, struct device, kobj);
  711. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  712. int ret;
  713. if (qlcnic_83xx_check(adapter))
  714. return QLC_STATUS_UNSUPPORTED_CMD;
  715. if (offset >= QLCNIC_MAX_PCI_FUNC)
  716. return QL_STATUS_INVALID_PARAM;
  717. ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
  718. QLCNIC_QUERY_RX_COUNTER);
  719. if (ret)
  720. return ret;
  721. ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
  722. QLCNIC_QUERY_TX_COUNTER);
  723. if (ret)
  724. return ret;
  725. return size;
  726. }
  727. static ssize_t qlcnic_sysfs_read_pci_config(struct file *file,
  728. struct kobject *kobj,
  729. struct bin_attribute *attr,
  730. char *buf, loff_t offset,
  731. size_t size)
  732. {
  733. struct device *dev = container_of(kobj, struct device, kobj);
  734. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  735. struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC];
  736. struct qlcnic_pci_info *pci_info;
  737. int i, ret;
  738. if (size != sizeof(pci_cfg))
  739. return QL_STATUS_INVALID_PARAM;
  740. pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
  741. if (!pci_info)
  742. return -ENOMEM;
  743. ret = qlcnic_get_pci_info(adapter, pci_info);
  744. if (ret) {
  745. kfree(pci_info);
  746. return ret;
  747. }
  748. memset(&pci_cfg, 0,
  749. sizeof(struct qlcnic_pci_func_cfg) * QLCNIC_MAX_PCI_FUNC);
  750. for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
  751. pci_cfg[i].pci_func = pci_info[i].id;
  752. pci_cfg[i].func_type = pci_info[i].type;
  753. pci_cfg[i].port_num = pci_info[i].default_port;
  754. pci_cfg[i].min_bw = pci_info[i].tx_min_bw;
  755. pci_cfg[i].max_bw = pci_info[i].tx_max_bw;
  756. memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN);
  757. }
  758. memcpy(buf, &pci_cfg, size);
  759. kfree(pci_info);
  760. return size;
  761. }
  762. static ssize_t qlcnic_83xx_sysfs_flash_read_handler(struct file *filp,
  763. struct kobject *kobj,
  764. struct bin_attribute *attr,
  765. char *buf, loff_t offset,
  766. size_t size)
  767. {
  768. unsigned char *p_read_buf;
  769. int ret, count;
  770. struct device *dev = container_of(kobj, struct device, kobj);
  771. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  772. if (!size)
  773. return QL_STATUS_INVALID_PARAM;
  774. if (!buf)
  775. return QL_STATUS_INVALID_PARAM;
  776. count = size / sizeof(u32);
  777. if (size % sizeof(u32))
  778. count++;
  779. p_read_buf = kcalloc(size, sizeof(unsigned char), GFP_KERNEL);
  780. if (!p_read_buf)
  781. return -ENOMEM;
  782. if (qlcnic_83xx_lock_flash(adapter) != 0) {
  783. kfree(p_read_buf);
  784. return -EIO;
  785. }
  786. ret = qlcnic_83xx_lockless_flash_read32(adapter, offset, p_read_buf,
  787. count);
  788. if (ret) {
  789. qlcnic_83xx_unlock_flash(adapter);
  790. kfree(p_read_buf);
  791. return ret;
  792. }
  793. qlcnic_83xx_unlock_flash(adapter);
  794. memcpy(buf, p_read_buf, size);
  795. kfree(p_read_buf);
  796. return size;
  797. }
  798. static int qlcnic_83xx_sysfs_flash_bulk_write(struct qlcnic_adapter *adapter,
  799. char *buf, loff_t offset,
  800. size_t size)
  801. {
  802. int i, ret, count;
  803. unsigned char *p_cache, *p_src;
  804. p_cache = kcalloc(size, sizeof(unsigned char), GFP_KERNEL);
  805. if (!p_cache)
  806. return -ENOMEM;
  807. memcpy(p_cache, buf, size);
  808. p_src = p_cache;
  809. count = size / sizeof(u32);
  810. if (qlcnic_83xx_lock_flash(adapter) != 0) {
  811. kfree(p_cache);
  812. return -EIO;
  813. }
  814. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  815. ret = qlcnic_83xx_enable_flash_write(adapter);
  816. if (ret) {
  817. kfree(p_cache);
  818. qlcnic_83xx_unlock_flash(adapter);
  819. return -EIO;
  820. }
  821. }
  822. for (i = 0; i < count / QLC_83XX_FLASH_WRITE_MAX; i++) {
  823. ret = qlcnic_83xx_flash_bulk_write(adapter, offset,
  824. (u32 *)p_src,
  825. QLC_83XX_FLASH_WRITE_MAX);
  826. if (ret) {
  827. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  828. ret = qlcnic_83xx_disable_flash_write(adapter);
  829. if (ret) {
  830. kfree(p_cache);
  831. qlcnic_83xx_unlock_flash(adapter);
  832. return -EIO;
  833. }
  834. }
  835. kfree(p_cache);
  836. qlcnic_83xx_unlock_flash(adapter);
  837. return -EIO;
  838. }
  839. p_src = p_src + sizeof(u32)*QLC_83XX_FLASH_WRITE_MAX;
  840. offset = offset + sizeof(u32)*QLC_83XX_FLASH_WRITE_MAX;
  841. }
  842. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  843. ret = qlcnic_83xx_disable_flash_write(adapter);
  844. if (ret) {
  845. kfree(p_cache);
  846. qlcnic_83xx_unlock_flash(adapter);
  847. return -EIO;
  848. }
  849. }
  850. kfree(p_cache);
  851. qlcnic_83xx_unlock_flash(adapter);
  852. return 0;
  853. }
  854. static int qlcnic_83xx_sysfs_flash_write(struct qlcnic_adapter *adapter,
  855. char *buf, loff_t offset, size_t size)
  856. {
  857. int i, ret, count;
  858. unsigned char *p_cache, *p_src;
  859. p_cache = kcalloc(size, sizeof(unsigned char), GFP_KERNEL);
  860. if (!p_cache)
  861. return -ENOMEM;
  862. memcpy(p_cache, buf, size);
  863. p_src = p_cache;
  864. count = size / sizeof(u32);
  865. if (qlcnic_83xx_lock_flash(adapter) != 0) {
  866. kfree(p_cache);
  867. return -EIO;
  868. }
  869. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  870. ret = qlcnic_83xx_enable_flash_write(adapter);
  871. if (ret) {
  872. kfree(p_cache);
  873. qlcnic_83xx_unlock_flash(adapter);
  874. return -EIO;
  875. }
  876. }
  877. for (i = 0; i < count; i++) {
  878. ret = qlcnic_83xx_flash_write32(adapter, offset, (u32 *)p_src);
  879. if (ret) {
  880. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  881. ret = qlcnic_83xx_disable_flash_write(adapter);
  882. if (ret) {
  883. kfree(p_cache);
  884. qlcnic_83xx_unlock_flash(adapter);
  885. return -EIO;
  886. }
  887. }
  888. kfree(p_cache);
  889. qlcnic_83xx_unlock_flash(adapter);
  890. return -EIO;
  891. }
  892. p_src = p_src + sizeof(u32);
  893. offset = offset + sizeof(u32);
  894. }
  895. if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) {
  896. ret = qlcnic_83xx_disable_flash_write(adapter);
  897. if (ret) {
  898. kfree(p_cache);
  899. qlcnic_83xx_unlock_flash(adapter);
  900. return -EIO;
  901. }
  902. }
  903. kfree(p_cache);
  904. qlcnic_83xx_unlock_flash(adapter);
  905. return 0;
  906. }
  907. static ssize_t qlcnic_83xx_sysfs_flash_write_handler(struct file *filp,
  908. struct kobject *kobj,
  909. struct bin_attribute *attr,
  910. char *buf, loff_t offset,
  911. size_t size)
  912. {
  913. int ret;
  914. static int flash_mode;
  915. unsigned long data;
  916. struct device *dev = container_of(kobj, struct device, kobj);
  917. struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
  918. if (!buf)
  919. return QL_STATUS_INVALID_PARAM;
  920. ret = kstrtoul(buf, 16, &data);
  921. switch (data) {
  922. case QLC_83XX_FLASH_SECTOR_ERASE_CMD:
  923. flash_mode = QLC_83XX_ERASE_MODE;
  924. ret = qlcnic_83xx_erase_flash_sector(adapter, offset);
  925. if (ret) {
  926. dev_err(&adapter->pdev->dev,
  927. "%s failed at %d\n", __func__, __LINE__);
  928. return -EIO;
  929. }
  930. break;
  931. case QLC_83XX_FLASH_BULK_WRITE_CMD:
  932. flash_mode = QLC_83XX_BULK_WRITE_MODE;
  933. break;
  934. case QLC_83XX_FLASH_WRITE_CMD:
  935. flash_mode = QLC_83XX_WRITE_MODE;
  936. break;
  937. default:
  938. if (flash_mode == QLC_83XX_BULK_WRITE_MODE) {
  939. ret = qlcnic_83xx_sysfs_flash_bulk_write(adapter, buf,
  940. offset, size);
  941. if (ret) {
  942. dev_err(&adapter->pdev->dev,
  943. "%s failed at %d\n",
  944. __func__, __LINE__);
  945. return -EIO;
  946. }
  947. }
  948. if (flash_mode == QLC_83XX_WRITE_MODE) {
  949. ret = qlcnic_83xx_sysfs_flash_write(adapter, buf,
  950. offset, size);
  951. if (ret) {
  952. dev_err(&adapter->pdev->dev,
  953. "%s failed at %d\n", __func__,
  954. __LINE__);
  955. return -EIO;
  956. }
  957. }
  958. }
  959. return size;
  960. }
  961. static struct device_attribute dev_attr_bridged_mode = {
  962. .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
  963. .show = qlcnic_show_bridged_mode,
  964. .store = qlcnic_store_bridged_mode,
  965. };
  966. static struct device_attribute dev_attr_diag_mode = {
  967. .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
  968. .show = qlcnic_show_diag_mode,
  969. .store = qlcnic_store_diag_mode,
  970. };
  971. static struct device_attribute dev_attr_beacon = {
  972. .attr = {.name = "beacon", .mode = (S_IRUGO | S_IWUSR)},
  973. .show = qlcnic_show_beacon,
  974. .store = qlcnic_store_beacon,
  975. };
  976. static struct bin_attribute bin_attr_crb = {
  977. .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
  978. .size = 0,
  979. .read = qlcnic_sysfs_read_crb,
  980. .write = qlcnic_sysfs_write_crb,
  981. };
  982. static struct bin_attribute bin_attr_mem = {
  983. .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
  984. .size = 0,
  985. .read = qlcnic_sysfs_read_mem,
  986. .write = qlcnic_sysfs_write_mem,
  987. };
  988. static struct bin_attribute bin_attr_npar_config = {
  989. .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)},
  990. .size = 0,
  991. .read = qlcnic_sysfs_read_npar_config,
  992. .write = qlcnic_sysfs_write_npar_config,
  993. };
  994. static struct bin_attribute bin_attr_pci_config = {
  995. .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)},
  996. .size = 0,
  997. .read = qlcnic_sysfs_read_pci_config,
  998. .write = NULL,
  999. };
  1000. static struct bin_attribute bin_attr_port_stats = {
  1001. .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)},
  1002. .size = 0,
  1003. .read = qlcnic_sysfs_get_port_stats,
  1004. .write = qlcnic_sysfs_clear_port_stats,
  1005. };
  1006. static struct bin_attribute bin_attr_esw_stats = {
  1007. .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)},
  1008. .size = 0,
  1009. .read = qlcnic_sysfs_get_esw_stats,
  1010. .write = qlcnic_sysfs_clear_esw_stats,
  1011. };
  1012. static struct bin_attribute bin_attr_esw_config = {
  1013. .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)},
  1014. .size = 0,
  1015. .read = qlcnic_sysfs_read_esw_config,
  1016. .write = qlcnic_sysfs_write_esw_config,
  1017. };
  1018. static struct bin_attribute bin_attr_pm_config = {
  1019. .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)},
  1020. .size = 0,
  1021. .read = qlcnic_sysfs_read_pm_config,
  1022. .write = qlcnic_sysfs_write_pm_config,
  1023. };
  1024. static struct bin_attribute bin_attr_flash = {
  1025. .attr = {.name = "flash", .mode = (S_IRUGO | S_IWUSR)},
  1026. .size = 0,
  1027. .read = qlcnic_83xx_sysfs_flash_read_handler,
  1028. .write = qlcnic_83xx_sysfs_flash_write_handler,
  1029. };
  1030. void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter)
  1031. {
  1032. struct device *dev = &adapter->pdev->dev;
  1033. if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_BDG)
  1034. if (device_create_file(dev, &dev_attr_bridged_mode))
  1035. dev_warn(dev,
  1036. "failed to create bridged_mode sysfs entry\n");
  1037. }
  1038. void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter)
  1039. {
  1040. struct device *dev = &adapter->pdev->dev;
  1041. if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_BDG)
  1042. device_remove_file(dev, &dev_attr_bridged_mode);
  1043. }
  1044. void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter)
  1045. {
  1046. struct device *dev = &adapter->pdev->dev;
  1047. if (device_create_bin_file(dev, &bin_attr_port_stats))
  1048. dev_info(dev, "failed to create port stats sysfs entry");
  1049. if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC)
  1050. return;
  1051. if (device_create_file(dev, &dev_attr_diag_mode))
  1052. dev_info(dev, "failed to create diag_mode sysfs entry\n");
  1053. if (device_create_bin_file(dev, &bin_attr_crb))
  1054. dev_info(dev, "failed to create crb sysfs entry\n");
  1055. if (device_create_bin_file(dev, &bin_attr_mem))
  1056. dev_info(dev, "failed to create mem sysfs entry\n");
  1057. if (device_create_bin_file(dev, &bin_attr_pci_config))
  1058. dev_info(dev, "failed to create pci config sysfs entry");
  1059. if (device_create_file(dev, &dev_attr_beacon))
  1060. dev_info(dev, "failed to create beacon sysfs entry");
  1061. if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
  1062. return;
  1063. if (device_create_bin_file(dev, &bin_attr_esw_config))
  1064. dev_info(dev, "failed to create esw config sysfs entry");
  1065. if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
  1066. return;
  1067. if (device_create_bin_file(dev, &bin_attr_npar_config))
  1068. dev_info(dev, "failed to create npar config sysfs entry");
  1069. if (device_create_bin_file(dev, &bin_attr_pm_config))
  1070. dev_info(dev, "failed to create pm config sysfs entry");
  1071. if (device_create_bin_file(dev, &bin_attr_esw_stats))
  1072. dev_info(dev, "failed to create eswitch stats sysfs entry");
  1073. }
  1074. void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter)
  1075. {
  1076. struct device *dev = &adapter->pdev->dev;
  1077. device_remove_bin_file(dev, &bin_attr_port_stats);
  1078. if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC)
  1079. return;
  1080. device_remove_file(dev, &dev_attr_diag_mode);
  1081. device_remove_bin_file(dev, &bin_attr_crb);
  1082. device_remove_bin_file(dev, &bin_attr_mem);
  1083. device_remove_bin_file(dev, &bin_attr_pci_config);
  1084. device_remove_file(dev, &dev_attr_beacon);
  1085. if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
  1086. return;
  1087. device_remove_bin_file(dev, &bin_attr_esw_config);
  1088. if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
  1089. return;
  1090. device_remove_bin_file(dev, &bin_attr_npar_config);
  1091. device_remove_bin_file(dev, &bin_attr_pm_config);
  1092. device_remove_bin_file(dev, &bin_attr_esw_stats);
  1093. }
  1094. void qlcnic_82xx_add_sysfs(struct qlcnic_adapter *adapter)
  1095. {
  1096. qlcnic_create_diag_entries(adapter);
  1097. }
  1098. void qlcnic_82xx_remove_sysfs(struct qlcnic_adapter *adapter)
  1099. {
  1100. qlcnic_remove_diag_entries(adapter);
  1101. }
  1102. void qlcnic_83xx_add_sysfs(struct qlcnic_adapter *adapter)
  1103. {
  1104. struct device *dev = &adapter->pdev->dev;
  1105. qlcnic_create_diag_entries(adapter);
  1106. if (sysfs_create_bin_file(&dev->kobj, &bin_attr_flash))
  1107. dev_info(dev, "failed to create flash sysfs entry\n");
  1108. }
  1109. void qlcnic_83xx_remove_sysfs(struct qlcnic_adapter *adapter)
  1110. {
  1111. struct device *dev = &adapter->pdev->dev;
  1112. qlcnic_remove_diag_entries(adapter);
  1113. sysfs_remove_bin_file(&dev->kobj, &bin_attr_flash);
  1114. }