zfcp_erp.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  1. /*
  2. * zfcp device driver
  3. *
  4. * Error Recovery Procedures (ERP).
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #include "zfcp_ext.h"
  9. #define ZFCP_MAX_ERPS 3
  10. enum zfcp_erp_act_flags {
  11. ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
  12. ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
  13. ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
  14. ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
  15. ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
  16. };
  17. enum zfcp_erp_steps {
  18. ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
  19. ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
  20. ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
  21. ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
  22. ZFCP_ERP_STEP_NAMESERVER_OPEN = 0x0200,
  23. ZFCP_ERP_STEP_NAMESERVER_LOOKUP = 0x0400,
  24. ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
  25. ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
  26. ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
  27. };
  28. enum zfcp_erp_act_type {
  29. ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
  30. ZFCP_ERP_ACTION_REOPEN_PORT = 2,
  31. ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
  32. ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
  33. };
  34. enum zfcp_erp_act_state {
  35. ZFCP_ERP_ACTION_RUNNING = 1,
  36. ZFCP_ERP_ACTION_READY = 2,
  37. };
  38. enum zfcp_erp_act_result {
  39. ZFCP_ERP_SUCCEEDED = 0,
  40. ZFCP_ERP_FAILED = 1,
  41. ZFCP_ERP_CONTINUES = 2,
  42. ZFCP_ERP_EXIT = 3,
  43. ZFCP_ERP_DISMISSED = 4,
  44. ZFCP_ERP_NOMEM = 5,
  45. };
  46. static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
  47. {
  48. zfcp_erp_modify_adapter_status(adapter, 15, NULL,
  49. ZFCP_STATUS_COMMON_UNBLOCKED | mask,
  50. ZFCP_CLEAR);
  51. }
  52. static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
  53. {
  54. struct zfcp_erp_action *curr_act;
  55. list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
  56. if (act == curr_act)
  57. return ZFCP_ERP_ACTION_RUNNING;
  58. return 0;
  59. }
  60. static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
  61. {
  62. struct zfcp_adapter *adapter = act->adapter;
  63. list_move(&act->list, &act->adapter->erp_ready_head);
  64. zfcp_rec_dbf_event_action(146, act);
  65. up(&adapter->erp_ready_sem);
  66. zfcp_rec_dbf_event_thread(2, adapter);
  67. }
  68. static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
  69. {
  70. act->status |= ZFCP_STATUS_ERP_DISMISSED;
  71. if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
  72. zfcp_erp_action_ready(act);
  73. }
  74. static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
  75. {
  76. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  77. zfcp_erp_action_dismiss(&unit->erp_action);
  78. }
  79. static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
  80. {
  81. struct zfcp_unit *unit;
  82. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  83. zfcp_erp_action_dismiss(&port->erp_action);
  84. else
  85. list_for_each_entry(unit, &port->unit_list_head, list)
  86. zfcp_erp_action_dismiss_unit(unit);
  87. }
  88. static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
  89. {
  90. struct zfcp_port *port;
  91. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  92. zfcp_erp_action_dismiss(&adapter->erp_action);
  93. else
  94. list_for_each_entry(port, &adapter->port_list_head, list)
  95. zfcp_erp_action_dismiss_port(port);
  96. }
  97. static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
  98. struct zfcp_port *port,
  99. struct zfcp_unit *unit)
  100. {
  101. int need = want;
  102. int u_status, p_status, a_status;
  103. switch (want) {
  104. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  105. u_status = atomic_read(&unit->status);
  106. if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  107. return 0;
  108. p_status = atomic_read(&port->status);
  109. if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
  110. p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
  111. return 0;
  112. if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
  113. need = ZFCP_ERP_ACTION_REOPEN_PORT;
  114. /* fall through */
  115. case ZFCP_ERP_ACTION_REOPEN_PORT:
  116. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  117. p_status = atomic_read(&port->status);
  118. if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  119. return 0;
  120. a_status = atomic_read(&adapter->status);
  121. if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
  122. a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
  123. return 0;
  124. if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
  125. need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
  126. /* fall through */
  127. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  128. a_status = atomic_read(&adapter->status);
  129. if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  130. return 0;
  131. }
  132. return need;
  133. }
  134. static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
  135. struct zfcp_adapter *adapter,
  136. struct zfcp_port *port,
  137. struct zfcp_unit *unit)
  138. {
  139. struct zfcp_erp_action *erp_action;
  140. u32 status = 0;
  141. switch (need) {
  142. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  143. zfcp_unit_get(unit);
  144. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
  145. erp_action = &unit->erp_action;
  146. if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
  147. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  148. break;
  149. case ZFCP_ERP_ACTION_REOPEN_PORT:
  150. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  151. zfcp_port_get(port);
  152. zfcp_erp_action_dismiss_port(port);
  153. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
  154. erp_action = &port->erp_action;
  155. if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
  156. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  157. break;
  158. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  159. zfcp_adapter_get(adapter);
  160. zfcp_erp_action_dismiss_adapter(adapter);
  161. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
  162. erp_action = &adapter->erp_action;
  163. if (!(atomic_read(&adapter->status) &
  164. ZFCP_STATUS_COMMON_RUNNING))
  165. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  166. break;
  167. default:
  168. return NULL;
  169. }
  170. memset(erp_action, 0, sizeof(struct zfcp_erp_action));
  171. erp_action->adapter = adapter;
  172. erp_action->port = port;
  173. erp_action->unit = unit;
  174. erp_action->action = need;
  175. erp_action->status = status;
  176. return erp_action;
  177. }
  178. static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
  179. struct zfcp_port *port,
  180. struct zfcp_unit *unit, u8 id, void *ref)
  181. {
  182. int retval = 1, need;
  183. struct zfcp_erp_action *act = NULL;
  184. if (!(atomic_read(&adapter->status) &
  185. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
  186. return -EIO;
  187. need = zfcp_erp_required_act(want, adapter, port, unit);
  188. if (!need)
  189. goto out;
  190. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
  191. act = zfcp_erp_setup_act(need, adapter, port, unit);
  192. if (!act)
  193. goto out;
  194. ++adapter->erp_total_count;
  195. list_add_tail(&act->list, &adapter->erp_ready_head);
  196. up(&adapter->erp_ready_sem);
  197. zfcp_rec_dbf_event_thread(1, adapter);
  198. retval = 0;
  199. out:
  200. zfcp_rec_dbf_event_trigger(id, ref, want, need, act,
  201. adapter, port, unit);
  202. return retval;
  203. }
  204. static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
  205. int clear_mask, u8 id, void *ref)
  206. {
  207. zfcp_erp_adapter_block(adapter, clear_mask);
  208. /* ensure propagation of failed status to new devices */
  209. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  210. zfcp_erp_adapter_failed(adapter, 13, NULL);
  211. return -EIO;
  212. }
  213. return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
  214. adapter, NULL, NULL, id, ref);
  215. }
  216. /**
  217. * zfcp_erp_adapter_reopen - Reopen adapter.
  218. * @adapter: Adapter to reopen.
  219. * @clear: Status flags to clear.
  220. * @id: Id for debug trace event.
  221. * @ref: Reference for debug trace event.
  222. */
  223. void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
  224. u8 id, void *ref)
  225. {
  226. unsigned long flags;
  227. read_lock_irqsave(&zfcp_data.config_lock, flags);
  228. write_lock(&adapter->erp_lock);
  229. _zfcp_erp_adapter_reopen(adapter, clear, id, ref);
  230. write_unlock(&adapter->erp_lock);
  231. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  232. }
  233. /**
  234. * zfcp_erp_adapter_shutdown - Shutdown adapter.
  235. * @adapter: Adapter to shut down.
  236. * @clear: Status flags to clear.
  237. * @id: Id for debug trace event.
  238. * @ref: Reference for debug trace event.
  239. */
  240. void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
  241. u8 id, void *ref)
  242. {
  243. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  244. zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
  245. }
  246. /**
  247. * zfcp_erp_port_shutdown - Shutdown port
  248. * @port: Port to shut down.
  249. * @clear: Status flags to clear.
  250. * @id: Id for debug trace event.
  251. * @ref: Reference for debug trace event.
  252. */
  253. void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, u8 id, void *ref)
  254. {
  255. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  256. zfcp_erp_port_reopen(port, clear | flags, id, ref);
  257. }
  258. /**
  259. * zfcp_erp_unit_shutdown - Shutdown unit
  260. * @unit: Unit to shut down.
  261. * @clear: Status flags to clear.
  262. * @id: Id for debug trace event.
  263. * @ref: Reference for debug trace event.
  264. */
  265. void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, u8 id, void *ref)
  266. {
  267. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  268. zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
  269. }
  270. static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
  271. {
  272. zfcp_erp_modify_port_status(port, 17, NULL,
  273. ZFCP_STATUS_COMMON_UNBLOCKED | clear,
  274. ZFCP_CLEAR);
  275. }
  276. static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
  277. int clear, u8 id, void *ref)
  278. {
  279. zfcp_erp_port_block(port, clear);
  280. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  281. return;
  282. zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
  283. port->adapter, port, NULL, id, ref);
  284. }
  285. /**
  286. * zfcp_erp_port_forced_reopen - Forced close of port and open again
  287. * @port: Port to force close and to reopen.
  288. * @id: Id for debug trace event.
  289. * @ref: Reference for debug trace event.
  290. */
  291. void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, u8 id,
  292. void *ref)
  293. {
  294. unsigned long flags;
  295. struct zfcp_adapter *adapter = port->adapter;
  296. read_lock_irqsave(&zfcp_data.config_lock, flags);
  297. write_lock(&adapter->erp_lock);
  298. _zfcp_erp_port_forced_reopen(port, clear, id, ref);
  299. write_unlock(&adapter->erp_lock);
  300. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  301. }
  302. static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id,
  303. void *ref)
  304. {
  305. zfcp_erp_port_block(port, clear);
  306. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  307. /* ensure propagation of failed status to new devices */
  308. zfcp_erp_port_failed(port, 14, NULL);
  309. return -EIO;
  310. }
  311. return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
  312. port->adapter, port, NULL, id, ref);
  313. }
  314. /**
  315. * zfcp_erp_port_reopen - trigger remote port recovery
  316. * @port: port to recover
  317. * @clear_mask: flags in port status to be cleared
  318. *
  319. * Returns 0 if recovery has been triggered, < 0 if not.
  320. */
  321. int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id, void *ref)
  322. {
  323. unsigned long flags;
  324. int retval;
  325. struct zfcp_adapter *adapter = port->adapter;
  326. read_lock_irqsave(&zfcp_data.config_lock, flags);
  327. write_lock(&adapter->erp_lock);
  328. retval = _zfcp_erp_port_reopen(port, clear, id, ref);
  329. write_unlock(&adapter->erp_lock);
  330. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  331. return retval;
  332. }
  333. static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
  334. {
  335. zfcp_erp_modify_unit_status(unit, 19, NULL,
  336. ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
  337. ZFCP_CLEAR);
  338. }
  339. static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id,
  340. void *ref)
  341. {
  342. struct zfcp_adapter *adapter = unit->port->adapter;
  343. zfcp_erp_unit_block(unit, clear);
  344. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  345. return;
  346. zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
  347. adapter, unit->port, unit, id, ref);
  348. }
  349. /**
  350. * zfcp_erp_unit_reopen - initiate reopen of a unit
  351. * @unit: unit to be reopened
  352. * @clear_mask: specifies flags in unit status to be cleared
  353. * Return: 0 on success, < 0 on error
  354. */
  355. void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id, void *ref)
  356. {
  357. unsigned long flags;
  358. struct zfcp_port *port = unit->port;
  359. struct zfcp_adapter *adapter = port->adapter;
  360. read_lock_irqsave(&zfcp_data.config_lock, flags);
  361. write_lock(&adapter->erp_lock);
  362. _zfcp_erp_unit_reopen(unit, clear, id, ref);
  363. write_unlock(&adapter->erp_lock);
  364. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  365. }
  366. static int status_change_set(unsigned long mask, atomic_t *status)
  367. {
  368. return (atomic_read(status) ^ mask) & mask;
  369. }
  370. static int status_change_clear(unsigned long mask, atomic_t *status)
  371. {
  372. return atomic_read(status) & mask;
  373. }
  374. static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
  375. {
  376. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
  377. zfcp_rec_dbf_event_adapter(16, NULL, adapter);
  378. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
  379. }
  380. static void zfcp_erp_port_unblock(struct zfcp_port *port)
  381. {
  382. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
  383. zfcp_rec_dbf_event_port(18, NULL, port);
  384. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
  385. }
  386. static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
  387. {
  388. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
  389. zfcp_rec_dbf_event_unit(20, NULL, unit);
  390. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
  391. }
  392. static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
  393. {
  394. list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
  395. zfcp_rec_dbf_event_action(145, erp_action);
  396. }
  397. static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
  398. {
  399. struct zfcp_adapter *adapter = act->adapter;
  400. if (!act->fsf_req)
  401. return;
  402. spin_lock(&adapter->req_list_lock);
  403. if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
  404. act->fsf_req->erp_action == act) {
  405. if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
  406. ZFCP_STATUS_ERP_TIMEDOUT)) {
  407. act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  408. zfcp_rec_dbf_event_action(142, act);
  409. }
  410. if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
  411. zfcp_rec_dbf_event_action(143, act);
  412. if (act->fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
  413. ZFCP_STATUS_FSFREQ_DISMISSED))
  414. act->fsf_req = NULL;
  415. } else
  416. act->fsf_req = NULL;
  417. spin_unlock(&adapter->req_list_lock);
  418. }
  419. /**
  420. * zfcp_erp_notify - Trigger ERP action.
  421. * @erp_action: ERP action to continue.
  422. * @set_mask: ERP action status flags to set.
  423. */
  424. void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
  425. {
  426. struct zfcp_adapter *adapter = erp_action->adapter;
  427. unsigned long flags;
  428. write_lock_irqsave(&adapter->erp_lock, flags);
  429. if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
  430. erp_action->status |= set_mask;
  431. zfcp_erp_action_ready(erp_action);
  432. }
  433. write_unlock_irqrestore(&adapter->erp_lock, flags);
  434. }
  435. /**
  436. * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
  437. * @data: ERP action (from timer data)
  438. */
  439. void zfcp_erp_timeout_handler(unsigned long data)
  440. {
  441. struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
  442. zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
  443. }
  444. static void zfcp_erp_memwait_handler(unsigned long data)
  445. {
  446. zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
  447. }
  448. static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
  449. {
  450. init_timer(&erp_action->timer);
  451. erp_action->timer.function = zfcp_erp_memwait_handler;
  452. erp_action->timer.data = (unsigned long) erp_action;
  453. erp_action->timer.expires = jiffies + HZ;
  454. add_timer(&erp_action->timer);
  455. }
  456. static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
  457. int clear, u8 id, void *ref)
  458. {
  459. struct zfcp_port *port;
  460. list_for_each_entry(port, &adapter->port_list_head, list)
  461. if (!(atomic_read(&port->status) & ZFCP_STATUS_PORT_WKA))
  462. _zfcp_erp_port_reopen(port, clear, id, ref);
  463. }
  464. static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear, u8 id,
  465. void *ref)
  466. {
  467. struct zfcp_unit *unit;
  468. list_for_each_entry(unit, &port->unit_list_head, list)
  469. _zfcp_erp_unit_reopen(unit, clear, id, ref);
  470. }
  471. static void zfcp_erp_strategy_followup_actions(struct zfcp_erp_action *act)
  472. {
  473. struct zfcp_adapter *adapter = act->adapter;
  474. struct zfcp_port *port = act->port;
  475. struct zfcp_unit *unit = act->unit;
  476. u32 status = act->status;
  477. /* initiate follow-up actions depending on success of finished action */
  478. switch (act->action) {
  479. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  480. if (status == ZFCP_ERP_SUCCEEDED)
  481. _zfcp_erp_port_reopen_all(adapter, 0, 70, NULL);
  482. else
  483. _zfcp_erp_adapter_reopen(adapter, 0, 71, NULL);
  484. break;
  485. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  486. if (status == ZFCP_ERP_SUCCEEDED)
  487. _zfcp_erp_port_reopen(port, 0, 72, NULL);
  488. else
  489. _zfcp_erp_adapter_reopen(adapter, 0, 73, NULL);
  490. break;
  491. case ZFCP_ERP_ACTION_REOPEN_PORT:
  492. if (status == ZFCP_ERP_SUCCEEDED)
  493. _zfcp_erp_unit_reopen_all(port, 0, 74, NULL);
  494. else
  495. _zfcp_erp_port_forced_reopen(port, 0, 75, NULL);
  496. break;
  497. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  498. if (status != ZFCP_ERP_SUCCEEDED)
  499. _zfcp_erp_port_reopen(unit->port, 0, 76, NULL);
  500. break;
  501. }
  502. }
  503. static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
  504. {
  505. unsigned long flags;
  506. read_lock_irqsave(&zfcp_data.config_lock, flags);
  507. read_lock(&adapter->erp_lock);
  508. if (list_empty(&adapter->erp_ready_head) &&
  509. list_empty(&adapter->erp_running_head)) {
  510. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  511. &adapter->status);
  512. wake_up(&adapter->erp_done_wqh);
  513. }
  514. read_unlock(&adapter->erp_lock);
  515. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  516. }
  517. static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
  518. {
  519. if (zfcp_qdio_open(act->adapter))
  520. return ZFCP_ERP_FAILED;
  521. init_waitqueue_head(&act->adapter->request_wq);
  522. atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
  523. return ZFCP_ERP_SUCCEEDED;
  524. }
  525. static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
  526. {
  527. struct zfcp_port *port;
  528. port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
  529. adapter->peer_d_id);
  530. if (IS_ERR(port)) /* error or port already attached */
  531. return;
  532. _zfcp_erp_port_reopen(port, 0, 150, NULL);
  533. }
  534. static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
  535. {
  536. int retries;
  537. int sleep = 1;
  538. struct zfcp_adapter *adapter = erp_action->adapter;
  539. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
  540. for (retries = 7; retries; retries--) {
  541. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  542. &adapter->status);
  543. write_lock_irq(&adapter->erp_lock);
  544. zfcp_erp_action_to_running(erp_action);
  545. write_unlock_irq(&adapter->erp_lock);
  546. if (zfcp_fsf_exchange_config_data(erp_action)) {
  547. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  548. &adapter->status);
  549. return ZFCP_ERP_FAILED;
  550. }
  551. zfcp_rec_dbf_event_thread_lock(6, adapter);
  552. down(&adapter->erp_ready_sem);
  553. zfcp_rec_dbf_event_thread_lock(7, adapter);
  554. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
  555. break;
  556. if (!(atomic_read(&adapter->status) &
  557. ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
  558. break;
  559. ssleep(sleep);
  560. sleep *= 2;
  561. }
  562. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  563. &adapter->status);
  564. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
  565. return ZFCP_ERP_FAILED;
  566. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  567. zfcp_erp_enqueue_ptp_port(adapter);
  568. return ZFCP_ERP_SUCCEEDED;
  569. }
  570. static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
  571. {
  572. int ret;
  573. struct zfcp_adapter *adapter = act->adapter;
  574. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  575. write_lock_irq(&adapter->erp_lock);
  576. zfcp_erp_action_to_running(act);
  577. write_unlock_irq(&adapter->erp_lock);
  578. ret = zfcp_fsf_exchange_port_data(act);
  579. if (ret == -EOPNOTSUPP)
  580. return ZFCP_ERP_SUCCEEDED;
  581. if (ret)
  582. return ZFCP_ERP_FAILED;
  583. zfcp_rec_dbf_event_thread_lock(8, adapter);
  584. down(&adapter->erp_ready_sem);
  585. zfcp_rec_dbf_event_thread_lock(9, adapter);
  586. if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
  587. return ZFCP_ERP_FAILED;
  588. return ZFCP_ERP_SUCCEEDED;
  589. }
  590. static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
  591. {
  592. if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
  593. return ZFCP_ERP_FAILED;
  594. if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
  595. return ZFCP_ERP_FAILED;
  596. atomic_set(&act->adapter->stat_miss, 16);
  597. if (zfcp_status_read_refill(act->adapter))
  598. return ZFCP_ERP_FAILED;
  599. return ZFCP_ERP_SUCCEEDED;
  600. }
  601. static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *act,
  602. int close)
  603. {
  604. int retval = ZFCP_ERP_SUCCEEDED;
  605. struct zfcp_adapter *adapter = act->adapter;
  606. if (close)
  607. goto close_only;
  608. retval = zfcp_erp_adapter_strategy_open_qdio(act);
  609. if (retval != ZFCP_ERP_SUCCEEDED)
  610. goto failed_qdio;
  611. retval = zfcp_erp_adapter_strategy_open_fsf(act);
  612. if (retval != ZFCP_ERP_SUCCEEDED)
  613. goto failed_openfcp;
  614. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &act->adapter->status);
  615. schedule_work(&act->adapter->scan_work);
  616. return ZFCP_ERP_SUCCEEDED;
  617. close_only:
  618. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  619. &act->adapter->status);
  620. failed_openfcp:
  621. /* close queues to ensure that buffers are not accessed by adapter */
  622. zfcp_qdio_close(adapter);
  623. zfcp_fsf_req_dismiss_all(adapter);
  624. adapter->fsf_req_seq_no = 0;
  625. /* all ports and units are closed */
  626. zfcp_erp_modify_adapter_status(adapter, 24, NULL,
  627. ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
  628. failed_qdio:
  629. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
  630. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  631. ZFCP_STATUS_ADAPTER_XPORT_OK,
  632. &act->adapter->status);
  633. return retval;
  634. }
  635. static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
  636. {
  637. int retval;
  638. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &act->adapter->status);
  639. zfcp_erp_adapter_strategy_generic(act, 1); /* close */
  640. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &act->adapter->status);
  641. if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  642. return ZFCP_ERP_EXIT;
  643. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &act->adapter->status);
  644. retval = zfcp_erp_adapter_strategy_generic(act, 0); /* open */
  645. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &act->adapter->status);
  646. if (retval == ZFCP_ERP_FAILED)
  647. ssleep(8);
  648. return retval;
  649. }
  650. static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
  651. {
  652. int retval;
  653. retval = zfcp_fsf_close_physical_port(act);
  654. if (retval == -ENOMEM)
  655. return ZFCP_ERP_NOMEM;
  656. act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
  657. if (retval)
  658. return ZFCP_ERP_FAILED;
  659. return ZFCP_ERP_CONTINUES;
  660. }
  661. static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
  662. {
  663. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
  664. ZFCP_STATUS_COMMON_CLOSING |
  665. ZFCP_STATUS_COMMON_ACCESS_DENIED |
  666. ZFCP_STATUS_PORT_DID_DID |
  667. ZFCP_STATUS_PORT_PHYS_CLOSING |
  668. ZFCP_STATUS_PORT_INVALID_WWPN,
  669. &port->status);
  670. }
  671. static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
  672. {
  673. struct zfcp_port *port = erp_action->port;
  674. int status = atomic_read(&port->status);
  675. switch (erp_action->step) {
  676. case ZFCP_ERP_STEP_UNINITIALIZED:
  677. zfcp_erp_port_strategy_clearstati(port);
  678. if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
  679. (status & ZFCP_STATUS_COMMON_OPEN))
  680. return zfcp_erp_port_forced_strategy_close(erp_action);
  681. else
  682. return ZFCP_ERP_FAILED;
  683. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  684. if (status & ZFCP_STATUS_PORT_PHYS_OPEN)
  685. return ZFCP_ERP_SUCCEEDED;
  686. }
  687. return ZFCP_ERP_FAILED;
  688. }
  689. static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
  690. {
  691. int retval;
  692. retval = zfcp_fsf_close_port(erp_action);
  693. if (retval == -ENOMEM)
  694. return ZFCP_ERP_NOMEM;
  695. erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
  696. if (retval)
  697. return ZFCP_ERP_FAILED;
  698. return ZFCP_ERP_CONTINUES;
  699. }
  700. static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
  701. {
  702. int retval;
  703. retval = zfcp_fsf_open_port(erp_action);
  704. if (retval == -ENOMEM)
  705. return ZFCP_ERP_NOMEM;
  706. erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
  707. if (retval)
  708. return ZFCP_ERP_FAILED;
  709. return ZFCP_ERP_CONTINUES;
  710. }
  711. static void zfcp_erp_port_strategy_open_ns_wake(struct zfcp_erp_action *ns_act)
  712. {
  713. unsigned long flags;
  714. struct zfcp_adapter *adapter = ns_act->adapter;
  715. struct zfcp_erp_action *act, *tmp;
  716. int status;
  717. read_lock_irqsave(&adapter->erp_lock, flags);
  718. list_for_each_entry_safe(act, tmp, &adapter->erp_running_head, list) {
  719. if (act->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
  720. status = atomic_read(&adapter->nameserver_port->status);
  721. if (status & ZFCP_STATUS_COMMON_ERP_FAILED)
  722. zfcp_erp_port_failed(act->port, 27, NULL);
  723. zfcp_erp_action_ready(act);
  724. }
  725. }
  726. read_unlock_irqrestore(&adapter->erp_lock, flags);
  727. }
  728. static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *act)
  729. {
  730. int retval;
  731. switch (act->step) {
  732. case ZFCP_ERP_STEP_UNINITIALIZED:
  733. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  734. case ZFCP_ERP_STEP_PORT_CLOSING:
  735. return zfcp_erp_port_strategy_open_port(act);
  736. case ZFCP_ERP_STEP_PORT_OPENING:
  737. if (atomic_read(&act->port->status) & ZFCP_STATUS_COMMON_OPEN)
  738. retval = ZFCP_ERP_SUCCEEDED;
  739. else
  740. retval = ZFCP_ERP_FAILED;
  741. /* this is needed anyway */
  742. zfcp_erp_port_strategy_open_ns_wake(act);
  743. return retval;
  744. default:
  745. return ZFCP_ERP_FAILED;
  746. }
  747. }
  748. static int zfcp_erp_port_strategy_open_lookup(struct zfcp_erp_action *act)
  749. {
  750. int retval;
  751. retval = zfcp_fc_ns_gid_pn_request(act);
  752. if (retval == -ENOMEM)
  753. return ZFCP_ERP_NOMEM;
  754. act->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
  755. if (retval)
  756. return ZFCP_ERP_FAILED;
  757. return ZFCP_ERP_CONTINUES;
  758. }
  759. static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
  760. {
  761. struct zfcp_adapter *adapter = act->adapter;
  762. struct zfcp_port *port = act->port;
  763. if (port->wwpn != adapter->peer_wwpn) {
  764. zfcp_erp_port_failed(port, 25, NULL);
  765. return ZFCP_ERP_FAILED;
  766. }
  767. port->d_id = adapter->peer_d_id;
  768. atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
  769. return zfcp_erp_port_strategy_open_port(act);
  770. }
  771. static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
  772. {
  773. struct zfcp_adapter *adapter = act->adapter;
  774. struct zfcp_port *port = act->port;
  775. struct zfcp_port *ns_port = adapter->nameserver_port;
  776. int p_status = atomic_read(&port->status);
  777. switch (act->step) {
  778. case ZFCP_ERP_STEP_UNINITIALIZED:
  779. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  780. case ZFCP_ERP_STEP_PORT_CLOSING:
  781. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  782. return zfcp_erp_open_ptp_port(act);
  783. if (!ns_port) {
  784. dev_err(&adapter->ccw_device->dev,
  785. "Attaching the name server port to the "
  786. "FCP device failed\n");
  787. return ZFCP_ERP_FAILED;
  788. }
  789. if (!(atomic_read(&ns_port->status) &
  790. ZFCP_STATUS_COMMON_UNBLOCKED)) {
  791. /* nameserver port may live again */
  792. atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
  793. &ns_port->status);
  794. if (zfcp_erp_port_reopen(ns_port, 0, 77, act) >= 0) {
  795. act->step = ZFCP_ERP_STEP_NAMESERVER_OPEN;
  796. return ZFCP_ERP_CONTINUES;
  797. }
  798. return ZFCP_ERP_FAILED;
  799. }
  800. /* else nameserver port is already open, fall through */
  801. case ZFCP_ERP_STEP_NAMESERVER_OPEN:
  802. if (!(atomic_read(&ns_port->status) & ZFCP_STATUS_COMMON_OPEN))
  803. return ZFCP_ERP_FAILED;
  804. return zfcp_erp_port_strategy_open_lookup(act);
  805. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  806. if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) {
  807. if (p_status & (ZFCP_STATUS_PORT_INVALID_WWPN)) {
  808. zfcp_erp_port_failed(port, 26, NULL);
  809. return ZFCP_ERP_EXIT;
  810. }
  811. return ZFCP_ERP_FAILED;
  812. }
  813. return zfcp_erp_port_strategy_open_port(act);
  814. case ZFCP_ERP_STEP_PORT_OPENING:
  815. /* D_ID might have changed during open */
  816. if ((p_status & ZFCP_STATUS_COMMON_OPEN) &&
  817. (p_status & ZFCP_STATUS_PORT_DID_DID))
  818. return ZFCP_ERP_SUCCEEDED;
  819. /* fall through otherwise */
  820. }
  821. return ZFCP_ERP_FAILED;
  822. }
  823. static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *act)
  824. {
  825. if (atomic_read(&act->port->status) & (ZFCP_STATUS_PORT_WKA))
  826. return zfcp_erp_port_strategy_open_nameserver(act);
  827. return zfcp_erp_port_strategy_open_common(act);
  828. }
  829. static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  830. {
  831. struct zfcp_port *port = erp_action->port;
  832. switch (erp_action->step) {
  833. case ZFCP_ERP_STEP_UNINITIALIZED:
  834. zfcp_erp_port_strategy_clearstati(port);
  835. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  836. return zfcp_erp_port_strategy_close(erp_action);
  837. break;
  838. case ZFCP_ERP_STEP_PORT_CLOSING:
  839. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  840. return ZFCP_ERP_FAILED;
  841. break;
  842. }
  843. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  844. return ZFCP_ERP_EXIT;
  845. else
  846. return zfcp_erp_port_strategy_open(erp_action);
  847. return ZFCP_ERP_FAILED;
  848. }
  849. static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  850. {
  851. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
  852. ZFCP_STATUS_COMMON_CLOSING |
  853. ZFCP_STATUS_COMMON_ACCESS_DENIED |
  854. ZFCP_STATUS_UNIT_SHARED |
  855. ZFCP_STATUS_UNIT_READONLY,
  856. &unit->status);
  857. }
  858. static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  859. {
  860. int retval = zfcp_fsf_close_unit(erp_action);
  861. if (retval == -ENOMEM)
  862. return ZFCP_ERP_NOMEM;
  863. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  864. if (retval)
  865. return ZFCP_ERP_FAILED;
  866. return ZFCP_ERP_CONTINUES;
  867. }
  868. static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  869. {
  870. int retval = zfcp_fsf_open_unit(erp_action);
  871. if (retval == -ENOMEM)
  872. return ZFCP_ERP_NOMEM;
  873. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  874. if (retval)
  875. return ZFCP_ERP_FAILED;
  876. return ZFCP_ERP_CONTINUES;
  877. }
  878. static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  879. {
  880. struct zfcp_unit *unit = erp_action->unit;
  881. switch (erp_action->step) {
  882. case ZFCP_ERP_STEP_UNINITIALIZED:
  883. zfcp_erp_unit_strategy_clearstati(unit);
  884. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  885. return zfcp_erp_unit_strategy_close(erp_action);
  886. /* already closed, fall through */
  887. case ZFCP_ERP_STEP_UNIT_CLOSING:
  888. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  889. return ZFCP_ERP_FAILED;
  890. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  891. return ZFCP_ERP_EXIT;
  892. return zfcp_erp_unit_strategy_open(erp_action);
  893. case ZFCP_ERP_STEP_UNIT_OPENING:
  894. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  895. return ZFCP_ERP_SUCCEEDED;
  896. }
  897. return ZFCP_ERP_FAILED;
  898. }
  899. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  900. {
  901. switch (result) {
  902. case ZFCP_ERP_SUCCEEDED :
  903. atomic_set(&unit->erp_counter, 0);
  904. zfcp_erp_unit_unblock(unit);
  905. break;
  906. case ZFCP_ERP_FAILED :
  907. atomic_inc(&unit->erp_counter);
  908. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
  909. dev_err(&unit->port->adapter->ccw_device->dev,
  910. "ERP failed for unit 0x%016Lx on "
  911. "port 0x%016Lx\n",
  912. unit->fcp_lun, unit->port->wwpn);
  913. zfcp_erp_unit_failed(unit, 21, NULL);
  914. }
  915. break;
  916. }
  917. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  918. zfcp_erp_unit_block(unit, 0);
  919. result = ZFCP_ERP_EXIT;
  920. }
  921. return result;
  922. }
  923. static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  924. {
  925. switch (result) {
  926. case ZFCP_ERP_SUCCEEDED :
  927. atomic_set(&port->erp_counter, 0);
  928. zfcp_erp_port_unblock(port);
  929. break;
  930. case ZFCP_ERP_FAILED :
  931. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
  932. zfcp_erp_port_block(port, 0);
  933. result = ZFCP_ERP_EXIT;
  934. }
  935. atomic_inc(&port->erp_counter);
  936. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
  937. dev_err(&port->adapter->ccw_device->dev,
  938. "ERP failed for remote port 0x%016Lx\n",
  939. port->wwpn);
  940. zfcp_erp_port_failed(port, 22, NULL);
  941. }
  942. break;
  943. }
  944. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  945. zfcp_erp_port_block(port, 0);
  946. result = ZFCP_ERP_EXIT;
  947. }
  948. return result;
  949. }
  950. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
  951. int result)
  952. {
  953. switch (result) {
  954. case ZFCP_ERP_SUCCEEDED :
  955. atomic_set(&adapter->erp_counter, 0);
  956. zfcp_erp_adapter_unblock(adapter);
  957. break;
  958. case ZFCP_ERP_FAILED :
  959. atomic_inc(&adapter->erp_counter);
  960. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
  961. dev_err(&adapter->ccw_device->dev,
  962. "ERP cannot recover an error "
  963. "on the FCP device\n");
  964. zfcp_erp_adapter_failed(adapter, 23, NULL);
  965. }
  966. break;
  967. }
  968. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  969. zfcp_erp_adapter_block(adapter, 0);
  970. result = ZFCP_ERP_EXIT;
  971. }
  972. return result;
  973. }
  974. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
  975. int result)
  976. {
  977. struct zfcp_adapter *adapter = erp_action->adapter;
  978. struct zfcp_port *port = erp_action->port;
  979. struct zfcp_unit *unit = erp_action->unit;
  980. switch (erp_action->action) {
  981. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  982. result = zfcp_erp_strategy_check_unit(unit, result);
  983. break;
  984. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  985. case ZFCP_ERP_ACTION_REOPEN_PORT:
  986. result = zfcp_erp_strategy_check_port(port, result);
  987. break;
  988. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  989. result = zfcp_erp_strategy_check_adapter(adapter, result);
  990. break;
  991. }
  992. return result;
  993. }
  994. static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
  995. {
  996. int status = atomic_read(target_status);
  997. if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
  998. (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  999. return 1; /* take it online */
  1000. if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
  1001. !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  1002. return 1; /* take it offline */
  1003. return 0;
  1004. }
  1005. static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
  1006. {
  1007. int action = act->action;
  1008. struct zfcp_adapter *adapter = act->adapter;
  1009. struct zfcp_port *port = act->port;
  1010. struct zfcp_unit *unit = act->unit;
  1011. u32 erp_status = act->status;
  1012. switch (action) {
  1013. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1014. if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
  1015. _zfcp_erp_adapter_reopen(adapter,
  1016. ZFCP_STATUS_COMMON_ERP_FAILED,
  1017. 67, NULL);
  1018. return ZFCP_ERP_EXIT;
  1019. }
  1020. break;
  1021. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1022. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1023. if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
  1024. _zfcp_erp_port_reopen(port,
  1025. ZFCP_STATUS_COMMON_ERP_FAILED,
  1026. 68, NULL);
  1027. return ZFCP_ERP_EXIT;
  1028. }
  1029. break;
  1030. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1031. if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
  1032. _zfcp_erp_unit_reopen(unit,
  1033. ZFCP_STATUS_COMMON_ERP_FAILED,
  1034. 69, NULL);
  1035. return ZFCP_ERP_EXIT;
  1036. }
  1037. break;
  1038. }
  1039. return ret;
  1040. }
  1041. static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  1042. {
  1043. struct zfcp_adapter *adapter = erp_action->adapter;
  1044. adapter->erp_total_count--;
  1045. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1046. adapter->erp_low_mem_count--;
  1047. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1048. }
  1049. list_del(&erp_action->list);
  1050. zfcp_rec_dbf_event_action(144, erp_action);
  1051. switch (erp_action->action) {
  1052. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1053. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  1054. &erp_action->unit->status);
  1055. break;
  1056. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1057. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1058. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  1059. &erp_action->port->status);
  1060. break;
  1061. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1062. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  1063. &erp_action->adapter->status);
  1064. break;
  1065. }
  1066. }
  1067. struct zfcp_erp_add_work {
  1068. struct zfcp_unit *unit;
  1069. struct work_struct work;
  1070. };
  1071. static void zfcp_erp_scsi_scan(struct work_struct *work)
  1072. {
  1073. struct zfcp_erp_add_work *p =
  1074. container_of(work, struct zfcp_erp_add_work, work);
  1075. struct zfcp_unit *unit = p->unit;
  1076. struct fc_rport *rport = unit->port->rport;
  1077. scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
  1078. unit->scsi_lun, 0);
  1079. atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1080. zfcp_unit_put(unit);
  1081. kfree(p);
  1082. }
  1083. static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
  1084. {
  1085. struct zfcp_erp_add_work *p;
  1086. p = kzalloc(sizeof(*p), GFP_KERNEL);
  1087. if (!p) {
  1088. dev_err(&unit->port->adapter->ccw_device->dev,
  1089. "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
  1090. unit->fcp_lun, unit->port->wwpn);
  1091. return;
  1092. }
  1093. zfcp_unit_get(unit);
  1094. atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1095. INIT_WORK(&p->work, zfcp_erp_scsi_scan);
  1096. p->unit = unit;
  1097. schedule_work(&p->work);
  1098. }
  1099. static void zfcp_erp_rport_register(struct zfcp_port *port)
  1100. {
  1101. struct fc_rport_identifiers ids;
  1102. ids.node_name = port->wwnn;
  1103. ids.port_name = port->wwpn;
  1104. ids.port_id = port->d_id;
  1105. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  1106. port->rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
  1107. if (!port->rport) {
  1108. dev_err(&port->adapter->ccw_device->dev,
  1109. "Registering port 0x%016Lx failed\n",
  1110. port->wwpn);
  1111. return;
  1112. }
  1113. scsi_target_unblock(&port->rport->dev);
  1114. port->rport->maxframe_size = port->maxframe_size;
  1115. port->rport->supported_classes = port->supported_classes;
  1116. }
  1117. static void zfcp_erp_rports_del(struct zfcp_adapter *adapter)
  1118. {
  1119. struct zfcp_port *port;
  1120. list_for_each_entry(port, &adapter->port_list_head, list)
  1121. if (port->rport && !(atomic_read(&port->status) &
  1122. ZFCP_STATUS_PORT_WKA)) {
  1123. fc_remote_port_delete(port->rport);
  1124. port->rport = NULL;
  1125. }
  1126. }
  1127. static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
  1128. {
  1129. struct zfcp_adapter *adapter = act->adapter;
  1130. struct zfcp_port *port = act->port;
  1131. struct zfcp_unit *unit = act->unit;
  1132. switch (act->action) {
  1133. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1134. if ((result == ZFCP_ERP_SUCCEEDED) &&
  1135. !unit->device && port->rport) {
  1136. atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
  1137. &unit->status);
  1138. if (!(atomic_read(&unit->status) &
  1139. ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
  1140. zfcp_erp_schedule_work(unit);
  1141. }
  1142. zfcp_unit_put(unit);
  1143. break;
  1144. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1145. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1146. if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN) {
  1147. zfcp_port_put(port);
  1148. return;
  1149. }
  1150. if ((result == ZFCP_ERP_SUCCEEDED) && !port->rport)
  1151. zfcp_erp_rport_register(port);
  1152. if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
  1153. fc_remote_port_delete(port->rport);
  1154. port->rport = NULL;
  1155. }
  1156. zfcp_port_put(port);
  1157. break;
  1158. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1159. if (result != ZFCP_ERP_SUCCEEDED)
  1160. zfcp_erp_rports_del(adapter);
  1161. zfcp_adapter_put(adapter);
  1162. break;
  1163. }
  1164. }
  1165. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1166. {
  1167. switch (erp_action->action) {
  1168. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1169. return zfcp_erp_adapter_strategy(erp_action);
  1170. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1171. return zfcp_erp_port_forced_strategy(erp_action);
  1172. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1173. return zfcp_erp_port_strategy(erp_action);
  1174. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1175. return zfcp_erp_unit_strategy(erp_action);
  1176. }
  1177. return ZFCP_ERP_FAILED;
  1178. }
  1179. static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
  1180. {
  1181. int retval;
  1182. struct zfcp_adapter *adapter = erp_action->adapter;
  1183. unsigned long flags;
  1184. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1185. write_lock(&adapter->erp_lock);
  1186. zfcp_erp_strategy_check_fsfreq(erp_action);
  1187. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1188. zfcp_erp_action_dequeue(erp_action);
  1189. retval = ZFCP_ERP_DISMISSED;
  1190. goto unlock;
  1191. }
  1192. zfcp_erp_action_to_running(erp_action);
  1193. /* no lock to allow for blocking operations */
  1194. write_unlock(&adapter->erp_lock);
  1195. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1196. retval = zfcp_erp_strategy_do_action(erp_action);
  1197. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1198. write_lock(&adapter->erp_lock);
  1199. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
  1200. retval = ZFCP_ERP_CONTINUES;
  1201. switch (retval) {
  1202. case ZFCP_ERP_NOMEM:
  1203. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1204. ++adapter->erp_low_mem_count;
  1205. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1206. }
  1207. if (adapter->erp_total_count == adapter->erp_low_mem_count)
  1208. _zfcp_erp_adapter_reopen(adapter, 0, 66, NULL);
  1209. else {
  1210. zfcp_erp_strategy_memwait(erp_action);
  1211. retval = ZFCP_ERP_CONTINUES;
  1212. }
  1213. goto unlock;
  1214. case ZFCP_ERP_CONTINUES:
  1215. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1216. --adapter->erp_low_mem_count;
  1217. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1218. }
  1219. goto unlock;
  1220. }
  1221. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1222. zfcp_erp_action_dequeue(erp_action);
  1223. retval = zfcp_erp_strategy_statechange(erp_action, retval);
  1224. if (retval == ZFCP_ERP_EXIT)
  1225. goto unlock;
  1226. zfcp_erp_strategy_followup_actions(erp_action);
  1227. unlock:
  1228. write_unlock(&adapter->erp_lock);
  1229. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1230. if (retval != ZFCP_ERP_CONTINUES)
  1231. zfcp_erp_action_cleanup(erp_action, retval);
  1232. return retval;
  1233. }
  1234. static int zfcp_erp_thread(void *data)
  1235. {
  1236. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  1237. struct list_head *next;
  1238. struct zfcp_erp_action *act;
  1239. unsigned long flags;
  1240. daemonize("zfcperp%s", adapter->ccw_device->dev.bus_id);
  1241. /* Block all signals */
  1242. siginitsetinv(&current->blocked, 0);
  1243. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1244. wake_up(&adapter->erp_thread_wqh);
  1245. while (!(atomic_read(&adapter->status) &
  1246. ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
  1247. write_lock_irqsave(&adapter->erp_lock, flags);
  1248. next = adapter->erp_ready_head.next;
  1249. write_unlock_irqrestore(&adapter->erp_lock, flags);
  1250. if (next != &adapter->erp_ready_head) {
  1251. act = list_entry(next, struct zfcp_erp_action, list);
  1252. /* there is more to come after dismission, no notify */
  1253. if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
  1254. zfcp_erp_wakeup(adapter);
  1255. }
  1256. zfcp_rec_dbf_event_thread(4, adapter);
  1257. down_interruptible(&adapter->erp_ready_sem);
  1258. zfcp_rec_dbf_event_thread(5, adapter);
  1259. }
  1260. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1261. wake_up(&adapter->erp_thread_wqh);
  1262. return 0;
  1263. }
  1264. /**
  1265. * zfcp_erp_thread_setup - Start ERP thread for adapter
  1266. * @adapter: Adapter to start the ERP thread for
  1267. *
  1268. * Returns 0 on success or error code from kernel_thread()
  1269. */
  1270. int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
  1271. {
  1272. int retval;
  1273. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1274. retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
  1275. if (retval < 0) {
  1276. dev_err(&adapter->ccw_device->dev,
  1277. "Creating an ERP thread for the FCP device failed.\n");
  1278. return retval;
  1279. }
  1280. wait_event(adapter->erp_thread_wqh,
  1281. atomic_read(&adapter->status) &
  1282. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
  1283. return 0;
  1284. }
  1285. /**
  1286. * zfcp_erp_thread_kill - Stop ERP thread.
  1287. * @adapter: Adapter where the ERP thread should be stopped.
  1288. *
  1289. * The caller of this routine ensures that the specified adapter has
  1290. * been shut down and that this operation has been completed. Thus,
  1291. * there are no pending erp_actions which would need to be handled
  1292. * here.
  1293. */
  1294. void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
  1295. {
  1296. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
  1297. up(&adapter->erp_ready_sem);
  1298. zfcp_rec_dbf_event_thread_lock(2, adapter);
  1299. wait_event(adapter->erp_thread_wqh,
  1300. !(atomic_read(&adapter->status) &
  1301. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
  1302. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  1303. &adapter->status);
  1304. }
  1305. /**
  1306. * zfcp_erp_adapter_failed - Set adapter status to failed.
  1307. * @adapter: Failed adapter.
  1308. * @id: Event id for debug trace.
  1309. * @ref: Reference for debug trace.
  1310. */
  1311. void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
  1312. {
  1313. zfcp_erp_modify_adapter_status(adapter, id, ref,
  1314. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1315. }
  1316. /**
  1317. * zfcp_erp_port_failed - Set port status to failed.
  1318. * @port: Failed port.
  1319. * @id: Event id for debug trace.
  1320. * @ref: Reference for debug trace.
  1321. */
  1322. void zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
  1323. {
  1324. zfcp_erp_modify_port_status(port, id, ref,
  1325. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1326. }
  1327. /**
  1328. * zfcp_erp_unit_failed - Set unit status to failed.
  1329. * @unit: Failed unit.
  1330. * @id: Event id for debug trace.
  1331. * @ref: Reference for debug trace.
  1332. */
  1333. void zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
  1334. {
  1335. zfcp_erp_modify_unit_status(unit, id, ref,
  1336. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1337. }
  1338. /**
  1339. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1340. * @adapter: adapter for which to wait for completion of its error recovery
  1341. */
  1342. void zfcp_erp_wait(struct zfcp_adapter *adapter)
  1343. {
  1344. wait_event(adapter->erp_done_wqh,
  1345. !(atomic_read(&adapter->status) &
  1346. ZFCP_STATUS_ADAPTER_ERP_PENDING));
  1347. }
  1348. /**
  1349. * zfcp_erp_modify_adapter_status - change adapter status bits
  1350. * @adapter: adapter to change the status
  1351. * @id: id for the debug trace
  1352. * @ref: reference for the debug trace
  1353. * @mask: status bits to change
  1354. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1355. *
  1356. * Changes in common status bits are propagated to attached ports and units.
  1357. */
  1358. void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
  1359. void *ref, u32 mask, int set_or_clear)
  1360. {
  1361. struct zfcp_port *port;
  1362. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1363. if (set_or_clear == ZFCP_SET) {
  1364. if (status_change_set(mask, &adapter->status))
  1365. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1366. atomic_set_mask(mask, &adapter->status);
  1367. } else {
  1368. if (status_change_clear(mask, &adapter->status))
  1369. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1370. atomic_clear_mask(mask, &adapter->status);
  1371. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1372. atomic_set(&adapter->erp_counter, 0);
  1373. }
  1374. if (common_mask)
  1375. list_for_each_entry(port, &adapter->port_list_head, list)
  1376. zfcp_erp_modify_port_status(port, id, ref, common_mask,
  1377. set_or_clear);
  1378. }
  1379. /**
  1380. * zfcp_erp_modify_port_status - change port status bits
  1381. * @port: port to change the status bits
  1382. * @id: id for the debug trace
  1383. * @ref: reference for the debug trace
  1384. * @mask: status bits to change
  1385. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1386. *
  1387. * Changes in common status bits are propagated to attached units.
  1388. */
  1389. void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
  1390. u32 mask, int set_or_clear)
  1391. {
  1392. struct zfcp_unit *unit;
  1393. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1394. if (set_or_clear == ZFCP_SET) {
  1395. if (status_change_set(mask, &port->status))
  1396. zfcp_rec_dbf_event_port(id, ref, port);
  1397. atomic_set_mask(mask, &port->status);
  1398. } else {
  1399. if (status_change_clear(mask, &port->status))
  1400. zfcp_rec_dbf_event_port(id, ref, port);
  1401. atomic_clear_mask(mask, &port->status);
  1402. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1403. atomic_set(&port->erp_counter, 0);
  1404. }
  1405. if (common_mask)
  1406. list_for_each_entry(unit, &port->unit_list_head, list)
  1407. zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
  1408. set_or_clear);
  1409. }
  1410. /**
  1411. * zfcp_erp_modify_unit_status - change unit status bits
  1412. * @unit: unit to change the status bits
  1413. * @id: id for the debug trace
  1414. * @ref: reference for the debug trace
  1415. * @mask: status bits to change
  1416. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1417. */
  1418. void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
  1419. u32 mask, int set_or_clear)
  1420. {
  1421. if (set_or_clear == ZFCP_SET) {
  1422. if (status_change_set(mask, &unit->status))
  1423. zfcp_rec_dbf_event_unit(id, ref, unit);
  1424. atomic_set_mask(mask, &unit->status);
  1425. } else {
  1426. if (status_change_clear(mask, &unit->status))
  1427. zfcp_rec_dbf_event_unit(id, ref, unit);
  1428. atomic_clear_mask(mask, &unit->status);
  1429. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1430. atomic_set(&unit->erp_counter, 0);
  1431. }
  1432. }
  1433. }
  1434. /**
  1435. * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
  1436. * @port: The "boxed" port.
  1437. * @id: The debug trace id.
  1438. * @id: Reference for the debug trace.
  1439. */
  1440. void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
  1441. {
  1442. unsigned long flags;
  1443. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1444. zfcp_erp_modify_port_status(port, id, ref,
  1445. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1446. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1447. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1448. }
  1449. /**
  1450. * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
  1451. * @port: The "boxed" unit.
  1452. * @id: The debug trace id.
  1453. * @id: Reference for the debug trace.
  1454. */
  1455. void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
  1456. {
  1457. zfcp_erp_modify_unit_status(unit, id, ref,
  1458. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1459. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1460. }
  1461. /**
  1462. * zfcp_erp_port_access_denied - Adapter denied access to port.
  1463. * @port: port where access has been denied
  1464. * @id: id for debug trace
  1465. * @ref: reference for debug trace
  1466. *
  1467. * Since the adapter has denied access, stop using the port and the
  1468. * attached units.
  1469. */
  1470. void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
  1471. {
  1472. unsigned long flags;
  1473. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1474. zfcp_erp_modify_port_status(port, id, ref,
  1475. ZFCP_STATUS_COMMON_ERP_FAILED |
  1476. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1477. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1478. }
  1479. /**
  1480. * zfcp_erp_unit_access_denied - Adapter denied access to unit.
  1481. * @unit: unit where access has been denied
  1482. * @id: id for debug trace
  1483. * @ref: reference for debug trace
  1484. *
  1485. * Since the adapter has denied access, stop using the unit.
  1486. */
  1487. void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
  1488. {
  1489. zfcp_erp_modify_unit_status(unit, id, ref,
  1490. ZFCP_STATUS_COMMON_ERP_FAILED |
  1491. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1492. }
  1493. static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id,
  1494. void *ref)
  1495. {
  1496. int status = atomic_read(&unit->status);
  1497. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1498. ZFCP_STATUS_COMMON_ACCESS_BOXED)))
  1499. return;
  1500. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1501. }
  1502. static void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id,
  1503. void *ref)
  1504. {
  1505. struct zfcp_unit *unit;
  1506. int status = atomic_read(&port->status);
  1507. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1508. ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
  1509. if (!(status & ZFCP_STATUS_PORT_WKA))
  1510. list_for_each_entry(unit, &port->unit_list_head, list)
  1511. zfcp_erp_unit_access_changed(unit, id, ref);
  1512. return;
  1513. }
  1514. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1515. }
  1516. /**
  1517. * zfcp_erp_adapter_access_changed - Process change in adapter ACT
  1518. * @adapter: Adapter where the Access Control Table (ACT) changed
  1519. * @id: Id for debug trace
  1520. * @ref: Reference for debug trace
  1521. */
  1522. void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
  1523. void *ref)
  1524. {
  1525. struct zfcp_port *port;
  1526. unsigned long flags;
  1527. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  1528. return;
  1529. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1530. if (adapter->nameserver_port)
  1531. zfcp_erp_port_access_changed(adapter->nameserver_port, id, ref);
  1532. list_for_each_entry(port, &adapter->port_list_head, list)
  1533. if (port != adapter->nameserver_port)
  1534. zfcp_erp_port_access_changed(port, id, ref);
  1535. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1536. }