zfcp_erp.c 47 KB

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