qlcnic_sysfs.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  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, drv_sds_rings = adapter->drv_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, drv_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 (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state))
  1058. return;
  1059. if (device_create_bin_file(dev, &bin_attr_pci_config))
  1060. dev_info(dev, "failed to create pci config sysfs entry");
  1061. if (device_create_file(dev, &dev_attr_beacon))
  1062. dev_info(dev, "failed to create beacon sysfs entry");
  1063. if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
  1064. return;
  1065. if (device_create_bin_file(dev, &bin_attr_esw_config))
  1066. dev_info(dev, "failed to create esw config sysfs entry");
  1067. if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
  1068. return;
  1069. if (device_create_bin_file(dev, &bin_attr_npar_config))
  1070. dev_info(dev, "failed to create npar config sysfs entry");
  1071. if (device_create_bin_file(dev, &bin_attr_pm_config))
  1072. dev_info(dev, "failed to create pm config sysfs entry");
  1073. if (device_create_bin_file(dev, &bin_attr_esw_stats))
  1074. dev_info(dev, "failed to create eswitch stats sysfs entry");
  1075. }
  1076. void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter)
  1077. {
  1078. struct device *dev = &adapter->pdev->dev;
  1079. device_remove_bin_file(dev, &bin_attr_port_stats);
  1080. if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC)
  1081. return;
  1082. device_remove_file(dev, &dev_attr_diag_mode);
  1083. device_remove_bin_file(dev, &bin_attr_crb);
  1084. device_remove_bin_file(dev, &bin_attr_mem);
  1085. if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state))
  1086. return;
  1087. device_remove_bin_file(dev, &bin_attr_pci_config);
  1088. device_remove_file(dev, &dev_attr_beacon);
  1089. if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
  1090. return;
  1091. device_remove_bin_file(dev, &bin_attr_esw_config);
  1092. if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
  1093. return;
  1094. device_remove_bin_file(dev, &bin_attr_npar_config);
  1095. device_remove_bin_file(dev, &bin_attr_pm_config);
  1096. device_remove_bin_file(dev, &bin_attr_esw_stats);
  1097. }
  1098. void qlcnic_82xx_add_sysfs(struct qlcnic_adapter *adapter)
  1099. {
  1100. qlcnic_create_diag_entries(adapter);
  1101. }
  1102. void qlcnic_82xx_remove_sysfs(struct qlcnic_adapter *adapter)
  1103. {
  1104. qlcnic_remove_diag_entries(adapter);
  1105. }
  1106. void qlcnic_83xx_add_sysfs(struct qlcnic_adapter *adapter)
  1107. {
  1108. struct device *dev = &adapter->pdev->dev;
  1109. qlcnic_create_diag_entries(adapter);
  1110. if (sysfs_create_bin_file(&dev->kobj, &bin_attr_flash))
  1111. dev_info(dev, "failed to create flash sysfs entry\n");
  1112. }
  1113. void qlcnic_83xx_remove_sysfs(struct qlcnic_adapter *adapter)
  1114. {
  1115. struct device *dev = &adapter->pdev->dev;
  1116. qlcnic_remove_diag_entries(adapter);
  1117. sysfs_remove_bin_file(&dev->kobj, &bin_attr_flash);
  1118. }